卡方检验是一种统计方法,用于确定两个类别变量之间是否具有显着相关性,这些变量都应来自相同的人群,并且应该是分类的,如-是/否,男性/女性,红色/绿色等,如,可以创建关于人们的冰淇淋购买模式的数据集,并尝试进行关联具有他们喜欢的冰淇淋口味的人的性别。
无涯教程使用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()
其输出如下-
链接:https://www.learnfk.comhttps://www.learnfk.com/python-data-science/python-chi-square-test.html
来源:LearnFk无涯教程网
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)