# 概率论10 方差与标准差

### 方差

$$Var(X) = E[(X - \mu)^2]$$

$$Var(X) = E[(X - \mu)^2] = \int_{-\infty}^{+\infty}(x-\mu)^2 f(x)dx$$

$$\sigma = \sqrt{Var(X)}$$

$$E(X) = \frac{1}{\sigma \sqrt{2 \pi}}\int_{-\infty}^{+\infty}xe^{-(x - \mu)^2/2 \sigma^2} dx$$

$$Var(X) = \sigma^2$$

# By Vamei

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

# Note the difference in "scale", which is std
rv1 = norm(loc=0, scale = 1)
rv2 = norm(loc=0, scale = 2)

x = np.linspace(-5, 5, 200)

plt.fill_between(x, rv1.pdf(x), y2=0.0, color="coral")
plt.fill_between(x, rv2.pdf(x), y2=0.0, color="green", alpha = 0.5)

plt.plot(x, rv1.pdf(x), color="red", label="N(0,1)")
plt.plot(x, rv2.pdf(x), color="blue", label="N(0,2)")

plt.legend()
plt.grid(True)

plt.xlim([-5, 5])
plt.ylim([-0.0, 0.5])

plt.title("normal distribution")
plt.xlabel("RV")
plt.ylabel("f(x)")

plt.show()

$$f(x) = \left\{ \begin{array}{rcl} \lambda e^{-\lambda x} & if & x \ge 0 \\ 0 & if & x < 0 \end{array} \right.$$

$$Var(X) = \frac{1}{\lambda^2}$$

### Chebyshev不等式

$$P( | X - \mu | > 2\sigma)$$

Chebyshev不等式让我们摆脱了对分布类型的依赖。它的叙述如下：

$$P( | X - \mu | > t) \le \frac{\sigma^2}{t}$$

$$P( | X - \mu | > 2\sigma) \le 0.25$$

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

# Note the difference in "scale", which is std
rv1 = norm(loc=0, scale = 1)

x1 = np.linspace(-5, -1, 100)
x2 = np.linspace(1, 5, 100)
x  = np.linspace(-5, 5, 200)
plt.fill_between(x1, rv1.pdf(x1), y2=0.0, color="coral")
plt.fill_between(x2, rv1.pdf(x2), y2=0.0, color="coral")
plt.plot(x, rv1.pdf(x), color="black", linewidth=2.0, label="N(0,1)")

plt.legend()
plt.grid(True)

plt.xlim([-5, 5])
plt.ylim([-0.0, 0.5])

plt.title("normal distribution")
plt.xlabel("RV")
plt.ylabel("f(x)")

plt.show()

### 总结

posted @ 2013-10-31 22:47  Vamei  阅读(18547)  评论(1编辑  收藏  举报