gpt4 book ai didi

python - 为什么 Scipy stdDev 返回错误的结果?

转载 作者:太空宇宙 更新时间:2023-11-03 13:45:58 24 4
gpt4 key购买 nike

import scipy

timeseries = [53.0, 28.0, 20.0, 113.0, 68.0, 18.0, 9.0, 72.0, 37.0, 29.0, 16.0, 70.0, 45.0, 3.0, 79.0, 7.0, 17.0, 0.0, 84.0, 19.0,
0.0, 1.0, 5.0, 16.0, 1485.3333, 650.0, 39.0, 52.0, 82.0, 13.0, 11.0, 14.0, 31.0, 20.0, 399.0, 124.0, 39.0, 0.0, 9.0,
42.0, 41.0, 98.5, 10.0, 4.0, 19.0, 53.0, 60.0, 789.0, 1471.3333, 876.0, 5.0, 714.0, 136.0, 27.0, 38.0, 29.0, 10.0,
181.0, 1.0, 14.0, 39.0, 29.0, 2.0, 1502.0, 174.5, 4.0, 305.0, 222.6667, 349.0, 38.0, 15.0, 168.0, 41.0, 28.0, 15.0,
508.0, 57.0, 26.0, 146.0, 50.5, 20.0, 12.0, 10.0, 15.0, 3.0, 19.0, 2922.0, 5200.5, 2989.0, 0.0, 5.0, 13.0, 2.0, 2.0,
4.0, 32.0, 66.0, 4.0, 36.0, 1.0, 6.0, 8.0, 88.0, 3.0, 7.0, 250.0, 0.5, 9.0, 0.0, 94.0, 16.0, 3.0, 6.0, 15.0, 4.0, 4.0,
240.0, 266.6667, 1208.0, 2387.0, 3883.5, 2997.3333, 2667.0, 417.5, 3.0, 26.0, 15.0, 11.0, 4.0, 70.0, 202.0, 2.0, 13.0,
3.0, 1.0, 6.0, 7.0, 5.0, 140.0, 954.0, 2343.0, 5264.6667, 6051.5, 1181.0, 489.5, 879.0, 1531.0, 2064.3333, 1472.0,
2029.3333, 3112.0, 2232.6667, 45.0, 716.5, 997.0, 1374.6667, 1993.5, 2549.0, 2690.5, 2640.3333, 2514.5, 1230.0, 475.5,
893.3333, 1984.5, 2054.3333, 1800.5, 2793.3333, 3630.5, 4305.3333, 5214.0, 5790.6667]

series = scipy.array(timeseries)
stdDev = scipy.std(series, dtype=scipy.float64)

print stdDev

返回 1246.16323355 而来自 Commons Math 的 Java 程序返回 1249.801674091763
如果我用 http://easycalculation.com/statistics/standard-deviation.php 检查它它还返回 1249.80167

Scipy 标准偏差有什么问题?

最佳答案

阅读 numpy.std 的文档字符串的注释部分(与 scipy.std 相同)。默认情况下,std 将偏差平方和除以 n。要获得与其他工具返回的值匹配的值,请使用 ddof=1,使其除以 n - 1:

In [2]: a = np.array(timeseries)

In [3]: std(a)
Out[3]: 1246.1632335502143

In [4]: std(a, ddof=1)
Out[4]: 1249.8016740917631

关于python - 为什么 Scipy stdDev 返回错误的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20637887/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com