📜  Python中的统计函数 |第 2 组(点差测量)

📅  最后修改于: 2022-05-13 01:54:34.082000             🧑  作者: Mango

Python中的统计函数 |第 2 组(点差测量)

Python中的统计函数 |第 1 组(中心位置的平均值和测量值)

本文讨论了统计量的传播函数。

1.variance() :-这个函数计算方差,即数据偏差的度量,方差值越大,数据值越分散。假设数据是总体的一部分,则在此函数中计算样本方差。如果传递的参数为空,则会引发StatisticsError

2. pvariance() :- 这个函数计算整个种群的方差。数据被解释为是整个人口的数据。如果传递的参数为空,则会引发StatisticsError

# Python code to demonstrate the working of 
# variance() and pvariance()
  
# importing statistics to handle statistical operations
import statistics
  
# initializing list
li = [1.5, 2.5, 2.5, 3.5, 3.5, 3.5]
  
# using variance to calculate variance of data
print ("The variance of data is : ",end="")
print (statistics.variance(li))
  
# using pvariance to calculate population variance of data
print ("The population variance of data is : ",end="")
print (statistics.pvariance(li))

输出:

The variance of data is : 0.6666666666666667
The population variance of data is : 0.5555555555555556

3. stdev() :- 该函数返回数据的标准偏差(样本方差的平方根) 。如果传递的参数为空,则会引发StatisticsError

4. pstdev() :- 该函数返回数据的总体标准差(总体方差的平方根) 。如果传递的参数为空,则会引发StatisticsError

# Python code to demonstrate the working of 
# stdev() and pstdev()
  
# importing statistics to handle statistical operations
import statistics
  
# initializing list
li = [1.5, 2.5, 2.5, 3.5, 3.5, 3.5]
  
# using stdev to calculate standard deviation of data
print ("The standard deviation of data is : ",end="")
print (statistics.stdev(li))
  
# using pstdev to calculate population standard deviation of data
print ("The population standard deviation of data is : ",end="")
print (statistics.pstdev(li))

输出:

The standard deviation of data is : 0.816496580927726
The population standard deviation of data is : 0.7453559924999299