卡方检验-python代码

故事背景

问题

卡方检验的结果怎么计算?

方法

python代码

python 复制代码
import numpy as np
from scipy.stats import chi2_contingency

# 观察频数矩阵
observed = np.array([[47, 21, 17],
                     [63, 29, 15],
                     [11, 2, 4]])

# 进行卡方检验
chi2, p, dof, expected = chi2_contingency(observed)

# 输出结果
print("输出结果:\n")
print(f"卡方统计量: {chi2}")
print(f"计算出的p值: {p}")
print(f"自由度: {dof}")
print("期望频数矩阵:")
print(expected)

运行结果

相关推荐
ZhengEnCi19 小时前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi20 小时前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽20 小时前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
用户83580861879121 小时前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python
Warson_L2 天前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅2 天前
海天线算法的前世今生
python·计算机视觉
韩师傅2 天前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L2 天前
LangGraph的MessageState and HumanMessage
python
韩师傅2 天前
当你的甲方吐槽天空不够蓝,你应该如何应对
python·计算机视觉
Warson_L2 天前
python的类&继承
python