大 pandas 与阴囊之间的偏斜和峰度功能有什么区别? [英] What is the difference between skew and kurtosis functions in pandas vs. scipy?

查看:69
本文介绍了大 pandas 与阴囊之间的偏斜和峰度功能有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定比较pandas和scipy.stats中的偏斜和峰度函数,但不明白为什么我在两个库之间得到不同的结果.

I decided to compare skew and kurtosis functions in pandas and scipy.stats, and don't understand why I'm getting different results between libraries.

据我所知,这两个峰度函数都是使用Fisher的定义进行计算的,而对于偏斜而言,似乎没有足够的描述来说明它们的计算方式是否存在重大差异.

As far as I can tell from the documentation, both kurtosis functions compute using Fisher's definition, whereas for skew there doesn't seem to be enough of a description to tell if there any major differences with how they are computed.

import pandas as pd
import scipy.stats.stats as st

heights = np.array([1.46, 1.79, 2.01, 1.75, 1.56, 1.69, 1.88, 1.76, 1.88, 1.78])

print "skewness:", st.skew(heights)
print "kurtosis:", st.kurtosis(heights)

这将返回:

skewness: -0.393524456473
kurtosis: -0.330672097724

而如果我转换为熊猫数据框:

whereas if I convert to a pandas dataframe:

heights_df = pd.DataFrame(heights)
print "skewness:", heights_df.skew()
print "kurtosis:", heights_df.kurtosis() 

这将返回:

skewness: 0   -0.466663
kurtosis: 0    0.379705

很抱歉,如果我在错误的位置发布了此信息;不确定是统计数据还是编程问题.

Apologies if I've posted this in the wrong place; not sure if it's a stats or a programming question.

推荐答案

差异归因于不同的规范化.默认情况下Scipy不能纠正偏见,而Pandas可以纠正.

The difference is due to different normalizations. Scipy by default does not correct for bias, whereas pandas does.

您可以通过传递bias=False参数来告诉scipy纠正偏差:

You can tell scipy to correct for bias by passing the bias=False argument:

>>> x = pandas.Series(np.random.randn(10))
>>> stats.skew(x)
-0.17644348972413657
>>> x.skew()
-0.20923623968879457
>>> stats.skew(x, bias=False)
-0.2092362396887948
>>> stats.kurtosis(x)
0.6362620964462327
>>> x.kurtosis()
2.0891062062174464
>>> stats.kurtosis(x, bias=False)
2.089106206217446

似乎没有一种方法告诉大熊猫删除偏差校正.

There does not appear to be a way to tell pandas to remove the bias correction.

这篇关于大 pandas 与阴囊之间的偏斜和峰度功能有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆