代码拉取完成,页面将自动刷新
同步操作将从 Higkoo/Book5_Essentials-of-Probability-and-Statistics 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
###############
# Authored by Weisheng Jiang
# Book 6 | From Basic Arithmetic to Machine Learning
# Published and copyrighted by Tsinghua University Press
# Beijing, China, 2022
###############
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
x = np.linspace(start = 0, stop = 16, num = 1000)
# In practice, population standard deviation is rarely known
n = 6
f_x_chi2 = stats.chi2.pdf(x, df = n-1)
alpha = 0.05
#%% Get the critical values, two-tailed
crit_value_right = stats.chi2.ppf(q = 1-alpha/2, df = n-1)
crit_value_left = stats.chi2.ppf(q = alpha/2, df = n-1)
fig, ax = plt.subplots()
plt.plot(x, f_x_chi2, color = "#0070C0")
plt.fill_between(x[np.logical_and(x >= crit_value_left, x <= crit_value_right)],
f_x_chi2[np.logical_and(x >= crit_value_left, x <= crit_value_right)],
color = "#DBEEF3")
ax.axvline(x = crit_value_right, color = 'r', linestyle = '--')
plt.plot(crit_value_right, 0,marker = 'x', color = 'k', markersize = 12)
ax.axvline(x = crit_value_left, color = 'r', linestyle = '--')
plt.plot(crit_value_left,0,marker = 'x', color = 'k', markersize = 12)
plt.fill_between(x[np.logical_and(x >= 0, x <= crit_value_left)],
f_x_chi2[np.logical_and(x >= 0, x <= crit_value_left)],
color = "#FF9980")
plt.fill_between(x[np.logical_and(x <= x.max(), x >= crit_value_right)],
f_x_chi2[np.logical_and(x <= x.max(), x >= crit_value_right)],
color = "#FF9980")
ax.set_xlim(0,16)
ax.set_ylim(0,0.2)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。