How to use the statistics.variance function in statistics

To help you get started, we’ve selected a few statistics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github trekhleb / learn-python / src / standard_libraries / test_math.py View on Github external
def test_statistics():
    """Statistics.

    The statistics module calculates basic statistical properties (the mean, median,
    variance, etc.) of numeric data.
    """

    data = [2.75, 1.75, 1.25, 0.25, 0.5, 1.25, 3.5]

    assert statistics.mean(data) == 1.6071428571428572
    assert statistics.median(data) == 1.25
    assert statistics.variance(data) == 1.3720238095238095
github lschoe / mpyc / tests / test_statistics.py View on Github external
x = list(map(secfxp, x))
        self.assertAlmostEqual(mpc.run(mpc.output(mean(x))), 3, delta=1)
        self.assertAlmostEqual(mpc.run(mpc.output(median(x))), 3)
        self.assertAlmostEqual(mpc.run(mpc.output(mode(x))), 4)

        x = [1, 1, 1, 1, 2, 2, 3, 4, 4, 4, 4, 5, 6, 6, 6] * 100
        random.shuffle(x)
        x = list(map(lambda a: a * 2**-4, x))
        x = list(map(secfxp, x))
        self.assertAlmostEqual(mpc.run(mpc.output(mean(x))), (2**-4) * 10/3, delta=1)

        y = [1.75, 1.25, -0.25, 0.5, 1.25, -3.5] * 5
        random.shuffle(y)
        x = list(map(secfxp, y))
        self.assertAlmostEqual(mpc.run(mpc.output(mean(x))), statistics.mean(y), 4)
        self.assertAlmostEqual(mpc.run(mpc.output(variance(x))), statistics.variance(y), 2)
        self.assertAlmostEqual(mpc.run(mpc.output(stdev(x))), statistics.stdev(y), 3)
        self.assertAlmostEqual(mpc.run(mpc.output(pvariance(x))), statistics.pvariance(y), 2)
        self.assertAlmostEqual(mpc.run(mpc.output(pstdev(x))), statistics.pstdev(y), 3)
        self.assertAlmostEqual(mpc.run(mpc.output(median(x))), statistics.median(y), 4)

        x = list(map(secfxp, [1.0]*10))
        self.assertAlmostEqual(mpc.run(mpc.output(mode(x))), 1)
        k = mpc.options.sec_param
        mpc.options.sec_param = 1  # force no privacy case
        self.assertAlmostEqual(mpc.run(mpc.output(mode(x))), 1)
        mpc.options.sec_param = k
github njali2001 / popsom / popsom.py View on Github external
def var_test(x, y, ratio=1, conf_level=0.95):

				DF_x = len(x) - 1
				DF_y = len(y) - 1
				V_x = stat.variance(x.tolist())
				V_y = stat.variance(y.tolist())

				ESTIMATE = V_x / V_y

				BETA = (1 - conf_level) / 2
				CINT = [ESTIMATE / f.ppf(1 - BETA, DF_x, DF_y),
						ESTIMATE / f.ppf(BETA, DF_x, DF_y)]

				return {"estimate": ESTIMATE, "conf_int": CINT}
github njali2001 / popsom / popsom.py View on Github external
def var_test(x, y, ratio=1, conf_level=0.95):

				DF_x = len(x) - 1
				DF_y = len(y) - 1
				V_x = stat.variance(x.tolist())
				V_y = stat.variance(y.tolist())

				ESTIMATE = V_x / V_y

				BETA = (1 - conf_level) / 2
				CINT = [ESTIMATE / f.ppf(1 - BETA, DF_x, DF_y),
						ESTIMATE / f.ppf(BETA, DF_x, DF_y)]

				return {"estimate": ESTIMATE, "conf_int": CINT}
github sk89q / plumeria / orchard / stats.py View on Github external
def variance(text):
    """
    Finds the variance of a space-separated list of numbers.

    Example::

        /variance 33 54 43 65 43 62
    """
    return format_output(statistics.variance(parse_numeric_list(text)))
github OpenVisualCloud / Ad-Insertion-Sample / ad-insertion / video-analytics-service / samples / sample.py View on Github external
def print_stats(status,key='avg_fps'):
    values = [x[key] for x in status if x and key in x and 'state' in x and x['state']=="COMPLETED"]

    if len(values):
        stats = {"value":key,
                 "Average":statistics.mean(values),
                 "Variance":statistics.variance(values),
                 "Max":max(values),
                 "Min":min(values),
                 "Count":len(status)
        }
        print_json(stats)
    else:
        print("No results")
github EventKit / eventkit-cloud / eventkit_cloud / utils / stats / generator.py View on Github external
def compute_stats_for(field):
        # Computes basic statistics for a single field (e.g. 'sizes')
        value_list = input_item.get(field)
        if value_list and len(value_list) > 0:
            st = dict()
            st['mean'] = statistics.mean(value_list)
            st['min'] = min(value_list)
            st['max'] = max(value_list)
            st['count'] = len(value_list)

            if len(value_list) >= 2:
                st['variance'] = statistics.variance(value_list, st['mean'])
                st['ci_90'] = get_confidence_interval(st['mean'], math.sqrt(st['variance']), st['count'], 1.645)
                st['ci_95'] = get_confidence_interval(st['mean'], math.sqrt(st['variance']), st['count'], 1.960)
                st['ci_99'] = get_confidence_interval(st['mean'], math.sqrt(st['variance']), st['count'], 2.580)

            target[field] = st
github django / django / django / db / backends / sqlite3 / base.py View on Github external
conn.create_function('REPEAT', 2, none_guard(operator.mul))
        conn.create_function('REVERSE', 1, none_guard(lambda x: x[::-1]))
        conn.create_function('RPAD', 3, _sqlite_rpad)
        conn.create_function('SHA1', 1, none_guard(lambda x: hashlib.sha1(x.encode()).hexdigest()))
        conn.create_function('SHA224', 1, none_guard(lambda x: hashlib.sha224(x.encode()).hexdigest()))
        conn.create_function('SHA256', 1, none_guard(lambda x: hashlib.sha256(x.encode()).hexdigest()))
        conn.create_function('SHA384', 1, none_guard(lambda x: hashlib.sha384(x.encode()).hexdigest()))
        conn.create_function('SHA512', 1, none_guard(lambda x: hashlib.sha512(x.encode()).hexdigest()))
        conn.create_function('SIGN', 1, none_guard(lambda x: (x > 0) - (x < 0)))
        conn.create_function('SIN', 1, none_guard(math.sin))
        conn.create_function('SQRT', 1, none_guard(math.sqrt))
        conn.create_function('TAN', 1, none_guard(math.tan))
        conn.create_aggregate('STDDEV_POP', 1, list_aggregate(statistics.pstdev))
        conn.create_aggregate('STDDEV_SAMP', 1, list_aggregate(statistics.stdev))
        conn.create_aggregate('VAR_POP', 1, list_aggregate(statistics.pvariance))
        conn.create_aggregate('VAR_SAMP', 1, list_aggregate(statistics.variance))
        conn.execute('PRAGMA foreign_keys = ON')
        return conn
github ahitrin / SiebenApp / doc / statistics / calculate.py View on Github external
def print_stats(label, data):
        med = int(statistics.median(data))
        var = statistics.variance(data)
        m = max(data)
        print("{}: max {}, median {}, variance {}".format(label, m, med, var))
github lab11 / powerblade / software / ble / pb_plus_wu.py View on Github external
print()
print("PLM True Power:\t\t\tPower Factor:")
print("Mean: " + str(round(mean_trueP,2)) + ',\t' + str(round(statistics.variance(truePower),4)),end="")
print("\t\t",end="")
print("Mean: " + str(round(mean_truePF,3)) + ',\t' + str(round(statistics.variance(trueFactor),4)))
print()
print("Watts Up True Power:\t\tPower Factor")
print("Mean: " + str(round(mean_wuP,2)) + ',\t' + str(round(statistics.variance(wuPower),4)),end="")
print("\t\t",end="")
print("Mean: " + str(round(mean_wuPF,3)) + ',\t' + str(round(statistics.variance(wuFactor),4)))
if mean_trueP > 0:
	print("Error: " + str(round(100*abs(mean_trueP-mean_wuP)/mean_trueP,2)))
print()
print("PowerBlade True Power:\t\tPower Factor")
print("Mean: " + str(round(mean_pbP,2)) + ',\t' + str(round(statistics.variance(pbPower),4)),end="")
print("\t\t",end="")
print("Mean: " + str(round(mean_pbPF,3)) + ',\t' + str(round(statistics.variance(pbFactor),4)))
if mean_trueP > 0:
	print("Error: " + str(round(100*abs(mean_trueP-mean_pbP)/mean_trueP,2)))
print()