python - 如何在 df=5 和 alpha=0.05 的 jupyter notebook 中绘制卡方图?
问题描述
如何在 jupyter notebook 中绘制卡方图?
它是双尾的,alpha = 0.05 和 df = 5
我只想绘制它并显示关键区域
解决方案
使用.interval
方法获取置信区间
In [1]: import scipy.stats as ss
In [2]: import matplotlib.pyplot as plt
In [3]: import numpy as np
# Distrubution object, chisqure with df=5
In [4]: dist = ss.chi2(5)
# Two tail C.I.
In [5]: dist.interval(0.95)
Out[5]: (0.831211613486663, 12.832501994030027)
In [7]: plt.plot(np.linspace(0,20), dist.pdf(np.linspace(0,20)))
Out[7]: [<matplotlib.lines.Line2D at 0x1a0e9fe048>]
In [10]: plt.vlines(dist.interval(0.95), ymin=0, ymax=plt.ylim()[1])
Out[10]: <matplotlib.collections.LineCollection at 0x1a16df7940>
In [11]: plt.show()
推荐阅读
- javascript - 未选中一个复选框时如何取消选中以下所有复选框
- apache-spark - Spark CountVectorizer 返回一个 TinyInt
- python - 将 Pygamescreens 高效加载到 2D 列表
- windows - unicode路径oledb问题
- javascript - 如何使用 Javascript 获取 JSON
- angularjs - 如何使用 Node js 在本地运行 AngularJS 1 应用程序?
- javascript - 服务器上的 Twilio Video Javascript
- android - INJECT_EVENTS 权限未授予特权应用程序
- java - 外键约束违反 JPA
- ios - AKNodeOutputPlot 无法与 Inter App Audio 一起正常工作