当前位置:   article > 正文

标准差计算公式_标准差的计算公式

标准差的计算公式

1.计算公式

总体:

样本:

2.python算法案例

2.1 借助numpy计算

总体:

  1. import numpy as np
  2. data1 = [25,15,13,26,31,17,16,4,41,12]
  3. data2 = [18,17,23,25,12,27,26,25,22,11]
  4. data3 = [7,18,12,9,32,29,21,22,13,14]
  5. print(np.std(data1), np.std(data2), np.std(data3))

10.207840124139876 5.499090833947008 7.874642849044012

样本:

  1. import numpy as np
  2. data1 = [25,15,13,26,31,17,16,4,41,12]
  3. data2 = [18,17,23,25,12,27,26,25,22,11]
  4. data3 = [7,18,12,9,32,29,21,22,13,14]
  5. print(np.std(data1,ddof=1), np.std(data2,ddof=1), np.std(data3,ddof=1))

10.760008261045982 5.796550698475775 8.300602387778852

2.2 按基础算

总体:

  1. data1 = [25,15,13,26,31,17,16,4,41,12]
  2. data2 = [18,17,23,25,12,27,26,25,22,11]
  3. data3 = [7,18,12,9,32,29,21,22,13,14]
  4. # 求平均值
  5. avg1 = sum(data1)/len(data1)
  6. avg2 = sum(data2)/len(data2)
  7. avg3 = sum(data3)/len(data3)
  8. data11 = list(map(lambda x: x - avg1, data1))
  9. data22 = list(map(lambda x: x - avg2, data2))
  10. data33 = list(map(lambda x: x - avg3, data3))
  11. data111 = list(map(lambda x: x**2, data11 ))
  12. data222 = list(map(lambda x: x**2, data22 ))
  13. data333 = list(map(lambda x: x**2, data22 ))
  14. c1 = math.sqrt(sum(data111 )/len(data1))
  15. c2 = math.sqrt(sum(data222 )/len(data2))
  16. c3 = math.sqrt(sum(data333 )/len(data3))
  17. print(c1, c2, c3)

10.207840124139876 5.499090833947008 7.874642849044013

样本:

  1. data1 = [25,15,13,26,31,17,16,4,41,12]
  2. data2 = [18,17,23,25,12,27,26,25,22,11]
  3. data3 = [7,18,12,9,32,29,21,22,13,14]
  4. # 求平均值
  5. avg1 = sum(data1)/len(data1)
  6. avg2 = sum(data2)/len(data2)
  7. avg3 = sum(data3)/len(data3)
  8. data11 = list(map(lambda x: x - avg1, data1))
  9. data22 = list(map(lambda x: x - avg2, data2))
  10. data33 = list(map(lambda x: x - avg3, data3))
  11. data111 = list(map(lambda x: x**2, data11 ))
  12. data222 = list(map(lambda x: x**2, data22 ))
  13. data333 = list(map(lambda x: x**2, data33 ))
  14. c1 = math.sqrt(sum(data111 )/(len(data1)-1))
  15. c2 = math.sqrt(sum(data222 )/(len(data2)-1))
  16. c3 = math.sqrt(sum(data333 )/(len(data3)-1))
  17. print(c1, c2, c3)

10.760008261045982 5.796550698475775 8.300602387778854

2.3 其他

  1. import numpy as np
  2. np.mean() # 可以用来求平均值
  3. np.sum() # 可以用来求和

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/695466
推荐阅读
相关标签
  

闽ICP备14008679号