代码拉取完成,页面将自动刷新
同步操作将从 Higkoo/Book5_Essentials-of-Probability-and-Statistics 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
###############
# Authored by Weisheng Jiang
# Book 5 | 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
from scipy.stats import norm
x = np.linspace(-3, 5, num=100)
# plot PDF
fig = plt.figure()
mean = 0
variance = 1
plt.plot(x, norm.pdf(x, loc=mean, scale=np.sqrt(variance)), label="$N(0, 1)$")
# The location (loc) keyword specifies the mean.
# The scale (scale) keyword specifies the standard deviation.
plt.axvline(x = mean, linestyle = '--', color = 'r')
mean = 2
variance = 3
plt.plot(x, norm.pdf(x, loc=mean, scale=np.sqrt(variance)), label="$N(2, 3)$")
plt.axvline(x = mean, linestyle = '--', color = 'r')
mean = -1
variance = 0.5
plt.plot(x, norm.pdf(x, loc=mean, scale=np.sqrt(variance)), label="$N(2, 3)$")
plt.axvline(x = mean, linestyle = '--', color = 'r')
plt.xlabel('$x$')
plt.ylabel('PDF, $f(x)$')
plt.ylim([0, 1])
plt.xlim([-3, 5])
plt.legend(loc=1)
# plot CDF curves
fig = plt.figure()
mean = 0
variance = 1
plt.plot(x, norm.cdf(x, loc=mean, scale=np.sqrt(variance)), label="$N(0, 1)$")
plt.axvline(x = mean, linestyle = '--', color = 'r')
mean = 2
variance = 3
plt.plot(x, norm.cdf(x, loc=mean, scale=np.sqrt(variance)), label="$N(2, 3)$")
plt.axvline(x = mean, linestyle = '--', color = 'r')
mean = -1
variance = 0.5
plt.plot(x, norm.cdf(x, loc=mean, scale=np.sqrt(variance)), label="$N(-1, 0.5)$")
plt.axvline(x = mean, linestyle = '--', color = 'r')
plt.axhline(y = 0.5, linestyle = '--', color = 'r')
plt.xlabel('$x$')
plt.ylabel('CDF, $F(x)$')
plt.ylim([0, 1])
plt.xlim([-3, 5])
plt.legend(loc=4)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。