Python 统计模块 pvariance() 方法
实例
计算整个总体的方差:
# Import statistics Library
import statistics
# Calculate the variance of an entire population
print(statistics.pvariance([1, 3, 5, 7, 9, 11]))
print(statistics.pvariance([2, 2.5, 1.25, 3.1, 1.75, 2.8]))
print(statistics.pvariance([-11, 5.5, -3.4, 7.1]))
print(statistics.pvariance([1, 30, 50, 100]))
定义与用法
statistics.pvariance()
方法计算整个总体的方差。
较大的方差表示数据分散,较小的方差表示数据紧密聚集在均值周围。
提示:要从数据样本计算方差,请查看 statistics.variance() 方法。
语法
statistics.pvariance(data, xbar)
参数值
参数 | 描述 |
---|---|
data | 必填的。要使用的数据值(可以是任何序列、列表或迭代器) |
xbar | 可选。给定数据的平均值(也可以是围绕非平均值点的第二个力矩)。如果省略(或设置为无),则自动计算平均值 |
注意:如果数据为空,则返回统计错误。
技术细节
返回值: | 一个 float 值,表示给定数据的总体方差 |
---|---|
Python 版本: | 3.4 |