【概率统计】S05E04连续型随机变量的分布与度量

# 1.概率密度函数

$P(X\in S)=\sum_{x\in S}{p_X(x)}=P_X(1)+P_X(2)+P_X(3)$。

$P(a\leq X\leq b)=P(a< X\leq b)=P(a\leq X< b)=P(a< X< b)$

$P(a\leq X \leq b)=\int_{-\infty}^{\infty} f_X(x)dx \leq 1$ 满足 $(a\leq b)$

# 2.连续型随机变量的期望与方差

$E[X]=\int_{-\infty}^{\infty} xf_X(x)dx$

$V[X]=E[(X-E[X])^2]=\int_{-\infty}^{\infty} (x-E[X])^2f_X(x)dx$

# 3.正态分布及正态随机变量

$f_X(x)=\frac{1}{\sqrt{2\pi}\sigma}e^{-(x-\mu)^2/(2\sigma^2)}$

from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots(1, 1)
norm_0 = norm(loc=0, scale=1)
norm_1 = norm(loc=1, scale=2)

x = np.linspace(-10,10, 1000)
ax.plot(x, norm_0.pdf(x), 'r-', lw=3, alpha=0.6, label='loc=0, scale=1')
ax.plot(x, norm_1.pdf(x), 'b-', lw=3, alpha=0.6, label='loc=1, scale=2')
ax.legend(loc='best', frameon=False)

plt.show()

from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots(1, 1)
norm_rv = norm(loc=2, scale=2)
norm_rvs = norm_rv.rvs(size=100000)
x = np.linspace(-10, 10, 1000)
ax.plot(x, norm_rv.pdf(x), 'r-', lw=3, alpha=0.6)
ax.hist(norm_rvs, normed=True, alpha=0.5)

plt.show()