• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python statistics.variance函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中statistics.variance函数的典型用法代码示例。如果您正苦于以下问题:Python variance函数的具体用法?Python variance怎么用?Python variance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了variance函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: run

def run(data):
    f = open("analyzer.log", 'a+')
    c = costs(data)
    total = total_cost(data)
    f.write("\n############# COST #############\n")
    f.write("Total Cost : {0}\n".format(total))
    f.write("Total Cost Mean: {0}\n".format(mean(c)))
    f.write("Total Cost Median: {0}\n".format(median(c)))
    f.write("Total Cost Mode: {0}\n".format(mode(c)))
    f.write("Total Cost Variance: {0}\n".format(variance(c)))

    cost_action = action(data)
    f.write("Cost by Action: \n")
    for k, v in cost_action.iteritems():
        f.write("\t{0} -> {1} units\n".format(k, v))

    f.write("Percentage Cost by Action: \n")
    for k, v in cost_action.iteritems():
        f.write("\t{0} -> {1} %\n".format(k, round(((v * 100.) / total), 2)))

    f.write("Cost Variance by Action: \n")
    for k, v in cost_action.iteritems():
        c_action = costs_action(data, k)
        if len(c_action) > 1:
            f.write("\t{0} -> {1} units\n".format(k, round(variance(c_action), 2)))
        else:
            f.write("\t{0} -> {1} units\n".format(k, round(c_action[0], 2)))

    key_max, max_value = max_action_value(cost_action)
    f.write("More Expensive Action by value: {0} -> {1}\n".format(key_max[0], cost_action.get(key_max[0])))

    key_max, max_value = max_action_percentage(cost_action, total)
    f.write("More Expensive Action by percentage: {0} -> {1} %\n".format(key_max, round(max_value, 2)))

    f.close()
开发者ID:I-am-Gabi,项目名称:jsontoxml,代码行数:35,代码来源:costs.py


示例2: model_analysis

def model_analysis(x, x_matrix, y, line, y_hat, b):
    n = len(x) # number of samples
    s_x = stats.stdev(x) # standard deviation of x values
    s_y = stats.stdev(y) # standard deviation of y values
    s2_x = stats.variance(x) # variance of x values
    s2_y = stats.variance(y) # variance of y values
    s_xy = b * s2_x # covariance of VM
    
    mad_temp = 0
    SSE = 0
    for i in range(len(y)):
        temp = abs(y[i] - y_hat[i])
        mad_temp += temp
        SSE += temp**2 # sum of squares for error
    MAD = mad_temp / n    
    s_err = math.sqrt(SSE / (n - 2)) # standard error of estimate
    s_b = s_err / math.sqrt((n - 1) * s2_x)
    
    r = s_xy / (s_x * s_y) # sample coefficient of correlation
    R_2 = line.score(x_matrix, y) # coefficient of determination 
    R_2calc = s_xy**2 / (s2_x * s2_y)
    t = b / s_b # t-value for slope assuming true slope = 0
    
    f1.write('\nSkew = ' + str(b) + '\n')
    f1.write('Coefficient of correlation (r) = ' + str(r) + '\n')
    #f1.write('Coefficient of determination (R^2) via scikit = ' + str(R_2) + '\n')
    f1.write('Coefficient of determination (R^2) calculate = ' + str(R_2calc) + '\n')
    f1.write('Test statistic for clock skew (t) = ' + str(t) + '\n')
    f1.write('Mean Absolute Deviation (MAD) = ' + str(MAD) + '\n')
    f1.write('Sum of Squares for Forecast Error (SSE) = ' + str(SSE) + '\n')
    
    return
开发者ID:cjwasek,项目名称:Traffic-Analysis-Project,代码行数:32,代码来源:SingleVM_Anal_v2.py


示例3: main

def main():

    statistics_file = open("statics.txt", "w")

    stats = {}

    final_statistics = {}

    entropy_kills = []
    entropy_dies = []

    initialize_server()

    stats = simulate_population()

    print(statistics)

    for key, val in stats.items() :
        entropy_kills += val[0]
        entropy_dies += val[1]

    print(str(entropy_kills))
    statistics_file.write(str(entropy_kills) + "\n")

    print(str(entropy_dies))
    statistics_file.write(str(entropy_dies) + "\n")


    final_statistics.update({"mean entropy kill " : statistics.mean(entropy_kills)})
    final_statistics.update({"variance entropy kill " : statistics.variance(entropy_kills)})
    final_statistics.update({"mean entropy_dies " : statistics.mean(entropy_dies) })
    final_statistics.update({"variance entropy_dies " : statistics.variance(entropy_dies) })

    for key, val in final_statistics.items():
        print(str(key) + " : " + str(val))
        statistics_file.write(str(key) + " : " + str(val) + "\n")

    plt.figure(1)

    plt.subplot(211)

    plt.xlabel('id bot')

    plt.ylabel('kill')

    plt.boxplot(entropy_kills, labels=list('K'))

    plt.subplot(212)

    plt.xlabel('id bot')

    plt.ylabel('dies')

    plt.boxplot(entropy_dies, labels=list('D'))

    plt.show()

    statistics_file.close()
开发者ID:DanieleGravina,项目名称:ProceduralWeapon,代码行数:58,代码来源:TestVariance.py


示例4: countXYZ

def countXYZ(data):
	x=[]
	y=[]
	z=[]
	for tmp in data:
		x.append(float(int(tmp[0:3],16))*12.0/4096.0)
		y.append(float(int(tmp[3:6],16))*14.0/4096.0)
		z.append(float(int(tmp[6:9],16))*36.0/4096.0)
	return [6.0-sum(x)/len(x),7.0-sum(y)/len(y),sum(z)/len(z),\
	statistics.variance(x),statistics.variance(y),statistics.variance(z)]
开发者ID:lengmi,项目名称:psd_c9069,代码行数:10,代码来源:DataAcquire.py


示例5: caculation

def caculation(data):
    trt_1 = data[data['trt'] == 1]
    trt_0 = data[data['trt'] == 0]
    
    medi = statistics.median(trt_1['y']) - statistics.median(trt_0['y'])
    mean = statistics.mean(trt_1['y']) - statistics.mean(trt_0['y'])
    peop = len(trt_1) + len(trt_0)
    vari = statistics.variance(trt_1['y']) + statistics.variance(trt_0['y'])
    z_stat, p_val = stats.ranksums(trt_0['y'], trt_1['y']) 
    return [medi, mean, peop, p_val]
开发者ID:c111190,项目名称:R,代码行数:10,代码来源:Ranksum_v1.py


示例6: adjRating

    def adjRating(self, ratings, VERBOSE=False):
        new_ratings = {}
        change = False
        max_change = 0.0
        for team in self.teams:
            # Set up arrays for ORating and DRating
            ODiff = []
            DDiff = []
            ct = self.teams[team]

            if VERBOSE:
                print("%s" % ct.name)
                print(" Home Games:")
            for game in ct.home_games:
                ODiff.append(game.hs + ratings[game.at.name][1])
                DDiff.append(game.aws - ratings[game.at.name][0])
                if VERBOSE:
                    print("  %s: "
                          "ODiff Entry=%.2f, "
                          "DDiff Entry=%.2f" % (game, ODiff[len(ODiff)-1],
                                              DDiff[len(DDiff)-1]))

            if VERBOSE:
                print(" Away Games:")
            for game in ct.away_games:
                ODiff.append(game.aws + ratings[game.ht.name][1])
                DDiff.append(game.hs - ratings[game.ht.name][0])
                if VERBOSE:
                    print("  %s: "
                          "ODiff Entry=%.2f, "
                          "DDiff Entry=%.2f" % (game, ODiff[len(ODiff)-1],
                                              DDiff[len(DDiff)-1]))

            temp_AdjO = (sum(ODiff)/float(len(ODiff))) - self.average
            temp_AdjD = self.average - (sum(DDiff)/float(len(DDiff)))
            ct.AOV = statistics.variance(ODiff)/len(ODiff)
            ct.ADV = statistics.variance(DDiff)/len(DDiff)
            new_ratings.update({ct.name: [temp_AdjO, temp_AdjD]})
            ch_th_O = abs((temp_AdjO-ratings[ct.name][0])/ratings[ct.name][0])
            ch_th_D = abs((temp_AdjD-ratings[ct.name][1])/ratings[ct.name][1])

            max_change = max(ch_th_D, ch_th_O, max_change)
            if ch_th_O > .0025 or ch_th_D > .0025:
                change = True
            if VERBOSE:
                print(" Team Stats")
                print("  AdjPointsScored: %s" % ODiff)
                print("  AdjPointsAllowed: %s" % DDiff)
                print("  AdjO=%.2f, AdjD=%.2f, "
                      "ChO=%.4f, ChD=%.4f" %
                      (temp_AdjO, temp_AdjD, ch_th_O, ch_th_D))
                print("  AOV=%.4f, ADV=%.4f" % (ct.AOV, ct.ADV))
        # print("%.4f" % max_change)
        return change, new_ratings
开发者ID:nluedtke,项目名称:LineIt,代码行数:54,代码来源:Season.py


示例7: get_statistics

    def get_statistics(self):
        """
        Returns various statistics about the benchmark run.
        :return: See description.
        """
        ret_val = {}
        not_applicable = 'N/A'

        if len(self.rollovers) > 1:  # Skip the last rollover...it could've been smaller than chunk_size
            rollover_times = []
            last_time = self.started
            for i in xrange(len(self.rollovers) - 1):
                rollover_times.append(
                    (self.rollovers[i] - last_time).total_seconds()
                )
                last_time = self.rollovers[i]

            ret_val['rollover_mean'] = self.num_to_seconds(mean(rollover_times))
            ret_val['rollover_stdev'] = self.num_to_seconds(stdev(rollover_times))
            ret_val['rollover_variance'] = self.num_to_seconds(variance(rollover_times))
        else:
            ret_val['rollover_mean'] = not_applicable
            ret_val['rollover_stdev'] = not_applicable
            ret_val['rollover_variance'] = not_applicable

        if self.initial_mem_usage is None:
            ret_val['initial_mem_usage'] = not_applicable
        else:
            ret_val['initial_mem_usage'] = self.num_to_megabytes(self.initial_mem_usage)

        if len(self.resources) > 0:
            cpu_util_list = [x[1] for x in self.resources]
            ret_val['cpu_util_mean'] = self.num_to_percent(mean(cpu_util_list))
            ret_val['cpu_util_stdev'] = self.num_to_percent(stdev(cpu_util_list))
            if len(cpu_util_list) > 1:
                ret_val['cpu_util_variance'] = self.num_to_percent(variance(cpu_util_list))
            else:
                ret_val['cpu_util_variance'] = not_applicable

            mem_usage_list = [x[2] for x in self.resources]
            ret_val['mem_usage_mean'] = self.num_to_megabytes(mean(mem_usage_list))
        else:
            ret_val['cpu_util_mean'] = not_applicable
            ret_val['cpu_util_stdev'] = not_applicable
            ret_val['cpu_util_variance'] = not_applicable

            ret_val['mem_usage_mean'] = not_applicable

        return ret_val
开发者ID:dfugate,项目名称:AnalyzeHdPerf,代码行数:49,代码来源:ClientInfo.py


示例8: DemoStatistic

def DemoStatistic(dataParam):

	#calculate mean
	mean = statistics.mean(dataParam);

	#calculate median
	median = statistics.median(dataParam);

	#calculate standard deviation
	stdv = statistics.variance(dataParam);

	#count values outside 3 sigma range
	noiseCount = 0;
	for value in dataParam:
		if value < (-3* stdv) + mean or value > (3*stdv) + mean:
			#print(" %.4f" %(value));
			noiseCount += 1;

			
	print("-----------------Simple------------------------");
	print("Data length: %d" %(len(dataParam)) );
	print("Values outside 3sigma: %d" %(noiseCount) );
	print("Mean: %.7f" %(mean));
	print("Median: %.7f"%(median));
	print("Standard deviation: %.7f"%(stdv));
	print("------------------------------------------------");
开发者ID:Kristijan10048,项目名称:diplomska,代码行数:26,代码来源:Statistic.py


示例9: analyze

def analyze(graphs):
    """summary stats for the graphs:
    >>> graphs = [{'win': ['a', 'b', 'philosophy']}, {'win': ['c', 'd', 'philosophy']}, {'fail': ['e', 'f', 'g', 'h', 'i', 'j', 'k']}]
    >>> analyze(graphs)
    ... {'min': 2, 'max': 2, 'mean': 2.0, 'median': 2.0, 'var': 0.0}
    """
    win_path_lengths = []
    fail_path_lengths = []

    for graph in graphs:
        if graph.get('win'):
            win_path_lengths.append(len(graph['win']) - 1)
        if graph.get('fail'):
            fail_path_lengths.append(len(graph['fail']) - 1)

    #stats
    win_perc = sum(win_path_lengths)/sum([sum(win_path_lengths), sum(fail_path_lengths)])
    min_path_length = min(win_path_lengths)
    max_path_length = max(win_path_lengths)
    mean_path_length = mean(win_path_lengths)
    median_path_length = median(win_path_lengths)
    var_path_length = variance(win_path_lengths)

    print('Cache is enabled by default, turning it off will affect the distributions')
    print('Percentage of pages leading to Philosophy: {}'.format(win_perc))
    print('Distribution of paths leading to Philosophy: min {}, max {}, mean {}, median {}, var {}'.format(
           min_path_length, max_path_length, mean_path_length, median_path_length, var_path_length))

    return dict(min=min_path_length,
                max=max_path_length,
                mean=mean_path_length,
                median=median_path_length,
                var=var_path_length)
开发者ID:mgcdanny,项目名称:spider,代码行数:33,代码来源:run.py


示例10: discard_spurious_lines

def discard_spurious_lines(lines, expected):
    """ Discards the discordant line(s).

    Discards the line or lines that minimizes the variance
    of the distances between the set of the other lines
    (of size expected).

    The hypothesis is that, when more lines than expected
    were detected, the variance of the distances bewteen
    lines will be minimized when the spurious lines are
    out of the set of selected lines.

    Be aware of the number of possible combinations before
    calling this function. Having just one or two extra lines
    should generally be ok.

    """
    best_variance = math.inf
    for combination in itertools.combinations(lines, expected):
        diffs = [b[0] - a[0]
                 for a, b in zip(combination[:-1], combination[1:])]
        variance = statistics.variance(diffs)
        if variance < best_variance:
            best_combination = combination
            best_variance = variance
    return best_combination
开发者ID:jfisteus,项目名称:eyegrade,代码行数:26,代码来源:geometry.py


示例11: makeCharactOutOfEndDifferencesList

def makeCharactOutOfEndDifferencesList(listdiffs, type=STAT_MEAN):
    """
    type=0, mean
    1, variance
    2, sigma
    """
    import copy
    import statistics
    import scipy.stats as scps

    lst = copy.deepcopy(listdiffs)

    func = {
        -1: statistics.median,
        0: statistics.mean,
        1: statistics.variance,
        2: lambda x: math.sqrt(statistics.variance(x)),
        3: scps.skewtest,
        4: scps.kurtosistest,
    }

    for j in range(len(lst)):
        for k in range(len(lst[j])):
            lst[j][k] = func[type](lst[j][k])

    return lst
开发者ID:reinerwaldmann,项目名称:PHDLinearization,代码行数:26,代码来源:MantissaEndDifferences.py


示例12: compute

 def compute(self, ydata):
     y = ydata.T
     var_y = statistics.variance(y)
     self.summary = self.summary+var_y
     self.var_y.append(var_y)
     return { 'summary': self.summary,
              'var_y': self.var_y }
开发者ID:mjvakili,项目名称:prob-z,代码行数:7,代码来源:statmcmc.py


示例13: async_update

    def async_update(self):
        """Get the latest data and updates the states."""
        if self._max_age is not None:
            self._purge_old()

        if not self.is_binary:
            try:  # require only one data point
                self.mean = round(statistics.mean(self.states), 2)
                self.median = round(statistics.median(self.states), 2)
            except statistics.StatisticsError as err:
                _LOGGER.error(err)
                self.mean = self.median = STATE_UNKNOWN

            try:  # require at least two data points
                self.stdev = round(statistics.stdev(self.states), 2)
                self.variance = round(statistics.variance(self.states), 2)
            except statistics.StatisticsError as err:
                _LOGGER.error(err)
                self.stdev = self.variance = STATE_UNKNOWN

            if self.states:
                self.count = len(self.states)
                self.total = round(sum(self.states), 2)
                self.min = min(self.states)
                self.max = max(self.states)
                self.change = self.states[-1] - self.states[0]
                self.average_change = self.change
                if len(self.states) > 1:
                    self.average_change /= len(self.states) - 1
                if self._max_age is not None:
                    self.max_age = max(self.ages)
                    self.min_age = min(self.ages)
            else:
                self.min = self.max = self.total = STATE_UNKNOWN
                self.average_change = self.change = STATE_UNKNOWN
开发者ID:DavidMStraub,项目名称:home-assistant,代码行数:35,代码来源:statistics.py


示例14: getVariances

def getVariances(optimalParameters):
    params = optimalParameters[0].keys()
    variances = {}
    for parameter in params:
        allValues = [x[parameter] for x in optimalParameters]
        variances[parameter] = statistics.variance(allValues)
    return variances
开发者ID:yetisir,项目名称:UpFrac2,代码行数:7,代码来源:parameterStatistics.py


示例15: get

 def get(self):
     values = sorted(self.reservoir.values)
     count = len(values)
     # instead of failing return empty / subset so that json2insert & co
     # don't fail
     if count == 0:
         return dict(n=0)
     elif count == 1:
         return dict(min=values[0], max=values[0], mean=values[0], n=count)
     percentiles = [percentile(values, p) for p in self.plevels]
     min_ = values[0]
     max_ = values[-1]
     stdev = statistics.stdev(values)
     return dict(
         min=min_,
         max=max_,
         mean=statistics.mean(values),
         median=statistics.median(values),
         variance=statistics.variance(values),
         error_margin=error_margin(95, stdev, self.reservoir.count),
         stdev=stdev,
         # replace . with _ so that the output can be inserted into crate
         # crate doesn't allow dots in column names
         percentile={str(i[0]).replace('.', '_'): i[1] for i in
                     zip(self.plevels, percentiles)},
         n=self.reservoir.count,
         samples=self.reservoir.values
     )
开发者ID:chaudum,项目名称:cr8,代码行数:28,代码来源:metrics.py


示例16: post_trigger_run

    def post_trigger_run(self, trigger: RawTrigger, main_plugin: MainPlugin, *args, **kwargs) -> None:
        """
        Collects the benchmark results and saves them in a file
        :param trigger: the trigger instance that is run
        :param main_plugin: the main plugin under which we run
        :param args: additional arguments
        :param kwargs: additional keyword arguments
        """
        if len(trigger.returned_information) == 1:
            mean = trigger.returned_information[0]
            stdev = 0
            variance = 0
        else:
            mean = statistics.mean(trigger.returned_information)
            stdev = statistics.stdev(trigger.returned_information)
            variance = statistics.variance(trigger.returned_information)

        if not os.path.exists(os.path.dirname(self.benchmark_log)):
            os.makedirs(os.path.dirname(self.benchmark_log))

        with open(self.benchmark_log, "a") as logs:
            logs.write("{name}, {plugin}, {slice_size}, {mean}, {stdev}, {variance} {total_numbers}\n".format(
                name=trigger.conf.get("name"),
                plugin=main_plugin.__class__.__name__,
                slice_size=kwargs.get("number", None),
                mean=mean,
                stdev=stdev,
                variance=variance,
                total_numbers=" ".join([str(data) for data in trigger.returned_information])))
开发者ID:AmesianX,项目名称:bugbase,代码行数:29,代码来源:benchmark.py


示例17: getVar

    def getVar(self):
        if(self.index == 1):
            return 0
        elif(self.index < self.N):
            return statistics.variance(self.window[0:self.index]) # Make return 0?

        return self.variance
开发者ID:jchrismer,项目名称:PiQuad,代码行数:7,代码来源:Inertial_Calibration.py


示例18: stats_of_tab

def stats_of_tab(fname):
    # Create a list of "statistics" objects, keyed by title from the spreadsheet
    tbl = []
    with open(fname, "r") as f:
        next(f) # Ignore first line, its just an index
        for line in f:
            cols = line.strip().split()
            title = cols[0]
            # Collect statistics on each row
            data = [int(x) for x in cols[1::]]
            obj = {}
            obj["key"] = cols[0]
            obj["num-samples"] = len(data)
            obj["mean"] = statistics.mean(data)
            obj["median"] = statistics.median(data)
            obj["min"] = min(data)
            obj["max"] = max(data)
            obj["range"] = obj["max"] - obj["min"]
            obj["std"] = statistics.stdev(data)
            obj["variance"] = statistics.variance(data)
            ci_offset = (Z95 * obj["std"]) / (math.sqrt(obj["num-samples"]))
            obj["confidence-interval"] = [obj["mean"] - ci_offset,
                                          obj["mean"] + ci_offset]
            tbl.append(obj)
    return tbl
开发者ID:bennn,项目名称:gradual-typing-performance,代码行数:25,代码来源:grouping.py


示例19: get_stats

def get_stats(arr):
    min_ = min(arr)
    max_ = max(arr)
    range_ = max_ - min_
    mean_ = statistics.mean(arr)
    median_ = statistics.median(arr)
    amp_ = max_ - mean_
    try:
        stdev_ = statistics.stdev(arr)
        var_ = statistics.variance(arr)
    except:
        stdev_ = 0
        var_ = 0
    rms_ = rms(arr)

    result = []
    result.append(min_)
    result.append(max_)
    result.append(range_)
    result.append(mean_)
    result.append(median_)
    result.append(amp_)
    result.append(stdev_)
    result.append(var_)
    result.append(rms_)
    return result
开发者ID:jsjessen,项目名称:school,代码行数:26,代码来源:loc_extract.py


示例20: test_parametric_variates

    def test_parametric_variates(self):
        """
        Verify the correctness of the random variates generation.
        :return: None
        """
        for variate in Variate:
            params = self.varparams[variate]
            sample = list()
            for i in range(self.samsize):
                rndvalue = Variate[variate.name].vargen.generate(u=self.rndgen, **params)
                sample.append(rndvalue)

            expected_mean = self.check_mean[variate](**params)
            actual_mean = mean(sample)
            print("{}: expected mean {}, got {}".format(variate.name, expected_mean, actual_mean))

            if self.makeAssertion:
                self.assertLessEqual(abs(expected_mean - actual_mean) / expected_mean,
                                     self.err * expected_mean,
                                     "Mean error for variate {}: expected {} got {}"
                                     .format(variate.name, expected_mean, actual_mean))

            expected_variance = self.check_variance[variate](**params)
            actual_variance = variance(sample)
            print("{}: expected variance {}, got {}".format(variate.name, expected_variance, actual_variance))

            if self.makeAssertion:
                self.assertLessEqual(abs(expected_variance - actual_variance) / expected_variance,
                                     self.err * expected_variance,
                                     "Variance error for variate {}: expected {} got {}"
                                     .format(variate.name, expected_variance, actual_variance))
开发者ID:gmarciani,项目名称:demule,代码行数:31,代码来源:test_rndvar.py



注:本文中的statistics.variance函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python statistics.Statistics类代码示例发布时间:2022-05-27
下一篇:
Python statistics.stdev函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap