← 返回题库
初级

绘制卡方分布

未完成 0%
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve():
    import numpy as np
    from scipy import stats
    from sklearn.datasets import load_iris
    iris = load_iris()
    sepal_length = iris.data[:, 0]
    n = len(sepal_length)
    std = np.std(sepal_length, ddof=1)
    # 方差的卡方置信区间
    chi2_low = stats.chi2.ppf(0.025, df=n-1)
    chi2_high = stats.chi2.ppf(0.975, df=n-1)
    ci_low = (n-1)*std**2 / chi2_high
    ci_high = (n-1)*std**2 / chi2_low
    print(f'{ci_low:.4f},{ci_high:.4f}')

示例

输入
solve()
期望输出
0.5733,0.8337
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码