卡方检验是一种统计方法,用于确定两个类别变量之间是否具有显着相关性。这些变量都应来自相同的人群,并且应该是分类的,例如-是/否,男性/女性,红色/绿色等。例如,我们可以使用对人们的冰淇淋购买模式的观察来构建数据集,并尝试进行关联具有他们喜欢的冰淇淋口味的人的性别。如果发现相关性,我们可以通过了解来访者的性别人数来计划适当的风味储备。

我们使用numpy库中的各种函数来进行卡方检验。.

from scipy import stats
import numpy as np
import matplotlib.pyplot as plt
 
x = np.linspace(0, 10, 100)
fig,ax = plt.subplots(1,1)
 
linestyles = [':', '--', '-.', '-']
deg_of_freedom = [1, 4, 7, 6]
for df, ls in zip(deg_of_freedom, linestyles):
  ax.plot(x, stats.chi2.pdf(x, df), linestyle=ls)
 
plt.xlim(0, 10)
plt.ylim(0, 0.4)
 
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.title('Chi-Square Distribution')
 
plt.legend()
plt.show()

python 卡方检验

感兴趣的小伙伴,可以扫码添加微信领取课程学习哦

python 卡方检验

相关文章:

  • 2021-10-06
  • 2021-12-28
  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-01
相关资源
相似解决方案