gpt4 book ai didi

python - 在scipy中如何计算峰度?

转载 作者:太空狗 更新时间:2023-10-30 02:10:48 26 4
gpt4 key购买 nike

我有这段代码可以使用我自己的代码计算峰度 ( http://mathworld.wolfram.com/Kurtosis.html ),并将其与 scipy.stats.kurtosis

进行比较
a = array([   1. ,    2. ,    2.5,  400. ,    6. ,    0. ])
#kurtosis (gives: 4.19886)
print (sum((a - np.mean(a)) ** 4)/len(a)) / np.std(a)**4
# scipy kurtosis (gives: 5.996677)
print scipy.stats.kurtosis(a,bias=False)

为什么 scipy 给出不同的结果?我遵循了 mathworld 中的定义。

最佳答案

如果您阅读 documentation scipy 的峰度函数,scipy 默认计算 Excess Kurtosis(负 3):

scipy.stats.kurtosis(a, axis=0, fisher=True, bias=True)

Computes the kurtosis (Fisher or Pearson) of a dataset.

Kurtosis is the fourth central moment divided by the square of the variance. If Fisher’s definition is used, then 3.0 is subtracted from the result to give 0.0 for a normal distribution.

If bias is False then the kurtosis is calculated using k statistics to eliminate bias coming from biased moment estimators

fisher 设置为 False 会得到您期望的结果:

In [1]: a = np.array([   1. ,    2. ,    2.5,  400. ,    6. ,    0. ])

In [2]: scipy.stats.kurtosis(a, fisher=False)
Out[2]: 4.198860780044809

关于python - 在scipy中如何计算峰度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26823968/

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