1 Star 0 Fork 53

fosterkong/Book5_Essentials-of-Probability-and-Statistics

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Bk5_Ch07_04.py 1.54 KB
一键复制 编辑 原始数据 按行查看 历史
Visualize-ML 提交于 2022-11-29 04:12 +08:00 . Add files via upload
###############
# Authored by Weisheng Jiang
# Book 5 | From Basic Arithmetic to Machine Learning
# Published and copyrighted by Tsinghua University Press
# Beijing, China, 2022
###############
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import t
from scipy.stats import norm
from matplotlib import cm # Colormaps
x = np.linspace(start = -5, stop = 5, num = 200)
# plot PDF curves
fig, ax = plt.subplots()
DFs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 25, 30]
colors = plt.cm.RdYlBu_r(np.linspace(0,1,len(DFs)))
for i in range(0,len(DFs)):
df = DFs[i]
plt.plot(x, t.pdf(x, df = df, loc = 0, scale = 1),
color = colors[int(i)],
label = "\u03BD = " + str(df))
ax.axvline(x = 0, color = 'k', linestyle = '--')
# compare with normal
plt.plot(x,norm.pdf(x,loc = 0, scale = 1), color = 'k', label = 'Normal')
plt.ylim((0, 0.5))
plt.xlim((-5,5))
plt.title("PDF of student's t")
plt.ylabel("PDF")
plt.legend()
plt.show()
# plot CDF curves
fig, ax = plt.subplots()
for i in range(0,len(DFs)):
df = DFs[i]
plt.plot(x, t.cdf(x, df = df, loc = 0, scale = 1),
color = colors[int(i)],
label = "\u03BD = " + str(df))
ax.axvline(x = 0, color = 'k', linestyle = '--')
ax.axhline(y = 0.5, color = 'k', linestyle = '--')
# compare with normal
plt.plot(x,norm.cdf(x,loc = 0, scale = 1), color = 'k', label = 'Normal')
plt.ylim((0, 1))
plt.xlim((-5,5))
plt.title("CDF of student's t")
plt.ylabel("CDF")
plt.legend()
plt.show()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/fosterkong/Book5_Essentials-of-Probability-and-Statistics.git
git@gitee.com:fosterkong/Book5_Essentials-of-Probability-and-Statistics.git
fosterkong
Book5_Essentials-of-Probability-and-Statistics
Book5_Essentials-of-Probability-and-Statistics
main

搜索帮助