[英]difference between pandas statistical functions and boost::accumulators
[英]Python Pandas find statistical difference between 2 distributions
我有2列相似的数据。 我绘制它们以比较它们的分布,并且我想量化它们之间的差异。
df = pd.DataFrame({'a':['cat','dog','bird','cat','dog','dog','dog'],
'b':['cat','cat','cat','bird','dog','dog','dog']})
然后,我绘制数据框的两列以比较它们的分布:
ax = df['a'].value_counts().plot(kind='bar', color='blue', width=.75, legend=True, alpha=0.8)
df['b'].value_counts().plot(kind='bar', color='maroon', width=.5, alpha=1, legend=True)
我该如何统计分布的差异,以说出它们之间的相似程度?
是简单的t检验还是其他?
为此,通常使用双面Kolmogorov-Smirnov检验 。
在Python中,您可以使用scipy.stats.ks_2samp
:
from scipy import stats
merged = pd.merge(
df.a.value_counts().to_frame(),
df.b.value_counts().to_frame(),
left_index=True,
right_index=True)
stats.ks_2samp(merged.a, merged.b)
广义地说,如果返回的元组的第二个值很小(例如小于0.05),则应拒绝分布相同的假设。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.