统计与机器学习 / 08

统计基础:分布、估计与相关性

从假设、目标到模型和评估。 统计基础:分布、估计与相关性。

阅读说明: 保留原笔记的编号与章节顺序;代码只供查看,没有在本站运行。历史输出不代表当前版本的复现结果。截图/外链图以独立整理的公式、表格、示意或文字替换;纠错与必要补充均作说明。

1. What is statistics?

1.1 two statistics

  • Descriptive statistics(描述性统计):整理,描述收集的数据特征
  • Inferential statistics(推论性统计):利用小群体的数据推论大群体的数据特征(样本smaple和总体population的关系)

1.2 Difference with probability

1.3 Difference with ML

  • statistical model: data-based
  • ML: 同样主要从数据中学习;与统计学的侧重不同,不能简单分成数据驱动与规则驱动

1.4 Simpson’s Paradox (辛普森悖论)

2. Population and Sample

  • Population:
    The entire collection of individuals or measurements about which information is desired.
  • Sample:
    A subset of the population selected for study. Primary objective is to create a subset of population whose center, spread and shape are as close as that of population.
  • Mthods of sampling:
    Random sampling, stratified sampling, systematic sampling, cluster sampling, multistage sampling, area sampling etc.

3. Parameter and Statistics

3.1 Parameter vs. Statistic

  • Parameter:
    Any statistical characteristic of a population.
  • Statistic (estimator):
    Any statistical characteristic of a sample.
    • How to estimate the mean parameter in a normal distribution?
      mean/median: It depends

3.2 Statistical inference

We sample the population (in a manner to ensure that the sample correctly represents the population) and then take measurements on our sample and infer (or generalize) back to the population.

4. A Taxonomy of statistics

统计描述的组织: 数值变量看形状、中心、离散程度和相对位置;类别变量看频数与比例。推断统计在抽样设计与模型假设下,从样本估计总体参数,并报告不确定性。

4.1 How does statistics describe data?

  • A numeric seta of data:
    Shape, Center, Variability
  • A categorical set of data:
    Frequency, percentage or proportion of each category

4.2 Variable

  • Categorical variable:
    • Nominal:
      Categorical variables with no inherent order or ranking sequence such as names or classes.
      Value may be a numerical, but without numerical value (e.g., I, II, III).
      The only operation that can be applied to nominal variables is enumeration.
    • Ordinal:
      Variables with an inherent order or rank, e.g. mild, moderate, severe.
      Can be compared for equality, or greater or less, but not how much greater or less.
  • Continuous variable:
    Variables with all properties of interval plus an absolute, non-arbitrary zero point, e.g. age, weight, temperature.
    Addition, subtraction, multiplication, and division are all meaningful operations.

整理注: 这里混合了变量类型与测量尺度:数值变量分离散/连续,测量尺度可分定类、定序、定距、定比;摄氏温度没有绝对零点,开尔文温度属于定比尺度。

4.3 Distribution

  • Umimodal: A single peak

分布形状示意: 单峰只有一个主要峰;双峰有两个主要峰;对称分布两侧近似镜像。右偏分布的右尾更长、均值往右尾移动;左偏则相反。偏斜度与单峰/双峰是不同描述维度,不能相互等同。

  • Bimodal: Two distinct peaks

  • Symmetric: Left and right half are mirror images

4.4 Numerical presentation

  • Center Measurement: mean & median
  • Variability Measurement: range, variance, standard deviation

5.Statistical description of data(需要背下来)

5.1 Mean and Variance

量总体样本估计
均值μ\muxˉ=∑ixi/n\bar x=\sum_i x_i/n
方差σ2=E[(X−μ)2]\sigma^2=E[(X-\mu)^2]s2=∑i(xi−xˉ)2/(n−1)s^2=\sum_i(x_i-\bar x)^2/(n-1)
标准差σ\sigmas=s2s=\sqrt{s^2}

独立同分布且方差有限时,上述样本方差无偏;样本标准差一般并非无偏估计。

其中估计的样本均值也是一个随机变量
n−1n-1: 无偏估计,意义是在多次重复下,它们的平均数接近所估计的参数真值

5.2 各种分布

5.2.1 伯努利分布

  • Probability Mass Function(概率质量函数:PMF):
f(k;p)={pif k=1q=1−pif k=0f(k;p) = \begin{cases} p & \text{if $ k=1 $} \\ q=1-p & \text{if $ k=0 $} \\ \end{cases}

概率质量函数(PMF)和概率密度函数(PDF)区别:

  • 概率质量函数是对离散随机变量定义的,本身代表该值的概率;
  • 概率密度函数是对连续随机变量定义的,本身不是概率,只有对连续随机变量的概率密度函数在某区间内进行积分后才是概率。
  • Mean: E(X)=pE(X)=p
  • Variance: Var(X)=pq=p(1−p)Var(X)=pq=p(1-p)

5.2.2 Uniform Distribution (均匀分布)

均匀分布示意: 在区间[a,b]内密度为水平线1/(b−a)1/(b-a),区间外为0。CDF在a前为0、a到b间线性增长、b后为1;全区间下的面积为1。

  • PDF:
f(x)={1b−a,a<x<b0,elsef(x) = \begin{cases} \frac{1}{b-a}, & a<x<b \\[2ex] 0, & \text{else} \\ \end{cases}
  • CDF:
F(x)={0,x<ax−ab−a,a≤x≤b1,x>bF(x) = \begin{cases} 0, & x<a \\[2ex] \frac{x-a}{b-a}, & a\leq{x}\leq{b} \\[2ex] 1, & x>b \\ \end{cases}
  • Mean: E(X)=(a+b)2E(X)=\frac{(a+b)}{2}
  • Variance: Var(X)=(b−a)212Var(X)=\frac{(b-a)^2}{12}

5.2.3 Binomial Distribution (二项分布)

  • PMF:
P(X=x)=Cnxpxqn−x,x=0,1,2,…,nP(X=x)=C^x_np^xq^{n-x},x=0,1,2,\ldots,n Cnx=n!(n−x)!x!C^x_n=\frac{n!}{(n-x)!x!}
  • Mean: E(X)=n⋅pE(X)=n\cdot{p}
  • Variance: Var(X)=n⋅p⋅qVar(X)=n\cdot{p}\cdot{q}

5.2.4 Poisson Distribution (泊松分布)

  • PMF:
P(X=k)=μkk!e−μ,  k=0,1,⋯P(X=k)=\frac{\mu^k}{k!}e^{-\mu}, \; k=0,1,\cdots

μ\mu表示单位时间(或单位面积)内随机事件的平均发生次数

  • Mean: E(X)=μE(X)=\mu
  • Variance: Var(X)=μVar(X)=\mu

5.3 Correlation

5.3.1 作用

两个或多个具备相关性的变量元素进行分析,从而衡量两个变量因素的相关密切程度

5.3.2 Pearson Correlation Coefficient

  • For Population:
ρX,Y=cov(X,Y)σXσY\rho_{X,Y}=\frac{cov(X,Y)}{\sigma_{X}\sigma_{Y}} cov(X,Y)=E[(X−μX)(Y−μY)]cov(X,Y)=\mathbb{E}[(X-\mu_X)(Y-\mu_Y)] 合并后:ρX,Y=E[XY]−E[X]E[Y]E[X2]−(E[X])2E[Y2]−(E[Y])2\text{合并后:}\rho_{X,Y}=\frac{\mathbb{E}[XY]-\mathbb{E}[X]\mathbb{E}[Y]}{\sqrt{\mathbb{E}[X^2]-(\mathbb{E}[X])^2}\sqrt{\mathbb{E}[Y^2]-(\mathbb{E}[Y])^2}}

μX=E[X],  μY=E[Y]\mu_X=\mathbb{E}[X], \; \mu_Y=\mathbb{E}[Y]
covcov: Covariance
σX\sigma_{X}: Standard deviation of X
σY\sigma_{Y}: Standard deviation of Y

  • For Sample:
rxy=∑i=1n(xi−xˉ)(yi−yˉ)∑i=1n(xi−xˉ)2∑i=1n(yi−yˉ)2r_{xy}=\frac{\sum^{n}_{i=1}{(x_i-\bar{x})(y_i-\bar{y})}}{\sqrt{\sum^{n}_{i=1}{(x_i-\bar{x})^2}}\sqrt{\sum^{n}_{i=1}{(y_i-\bar{y})^2}}}

5.3.3 Some basic theorems

  1. 期望:
    • E(c)=c,  c=const\mathbb{E}(c)=c, \; c=const
    • E(X±Y)=E(X)±E(Y)\mathbb{E}(X\pm{Y})=\mathbb{E}(X)\pm{\mathbb{E}(Y)}
    • X, Y相互独立: E(XY)=E(X)E(Y)\mathbb{E}(XY)=\mathbb{E}(X)\mathbb{E}(Y)
  2. 方差: σ2=Var(X)\sigma^2=Var(X)
    • Var(c)=0,  c=constVar(c)=0, \; c=const
    • Var(cX)=c2⋅Var(X),  c=constVar(cX)=c^2\cdot{Var(X)}, \; c=const
    • Var(X+c)=Var(X),  c=constVar(X+c)=Var(X), \; c=const
    • Var(cX+a)=c2⋅Var(X),  c,a=constVar(cX+a)=c^2\cdot{Var(X)}, \; c,a=const
    • X, Y相互独立(±→+\pm\to{+}): Var(X±Y)=Var(X)+Var(Y)Var(X\pm{Y})=Var(X)+Var(Y)
  3. 期望与方差关系: Var(X)=E(X2)−[E(X)]2Var(X)=\mathbb{E}(X^2)-[\mathbb{E}(X)]^2
    推导:
Var(X)=E[X−E(X)]2=E[X2−2X⋅E(X)+(E(X))2]=E(X2)−2E(X)⋅E(X)+[E(X)]2=E(X2)−[E(X)]2\begin{aligned} Var(X) & = \mathbb{E}[X-\mathbb{E}(X)]^2 \\ & = \mathbb{E}[X^2-2X\cdot\mathbb{E}(X)+(\mathbb{E}(X))^2] \\ & = \mathbb{E}(X^2)-2\mathbb{E}(X)\cdot\mathbb{E}(X)+[\mathbb{E}(X)]^2 \\ & = \mathbb{E}(X^2)-[\mathbb{E}(X)]^2 \end{aligned}
  1. 期望与协方差关系: Cov(X,Y)=E(XY)−E(X)E(Y)Cov(X,Y)=\mathbb{E}(XY)-\mathbb{E}(X)\mathbb{E}(Y)
    推导:
Cov(X,Y)=E[(X−μX)(Y−μY)]=E(XY−μXY−μYX+μXμY)=E(XY)−E(μXY)−E(μYX)+μXμY=E(XY)−μXE(Y)−μYE(X)+μXμY=E(XY)−μXμY−μYμX+μXμY=E(XY)−μXμY=E(XY)−E(X)E(Y)\begin{aligned} Cov(X,Y) & = \mathbb{E}[(X-\mu_X)(Y-\mu_Y)] \\ & = \mathbb{E}(XY-\mu_X{Y}-\mu_Y{X}+\mu_X\mu_Y) \\ & = \mathbb{E}(XY)-\mathbb{E}(\mu_X{Y})-\mathbb{E}(\mu_Y{X})+\mu_X\mu_Y \\ & = \mathbb{E}(XY)-\mu_X\mathbb{E}(Y)-\mu_Y\mathbb{E}(X)+\mu_X\mu_Y \\ & = \mathbb{E}(XY)-\mu_X\mu_Y-\mu_Y\mu_X+\mu_X\mu_Y \\ & = \mathbb{E}(XY)-\mu_X\mu_Y \\ & = \mathbb{E}(XY)-\mathbb{E}(X)\mathbb{E}(Y) \end{aligned}
  1. Independence
    • Cov(X,Y)=0Cov(X,Y)=0 When X is independent of Y
    • ρX,Y=0\rho_{X,Y}=0 When X is independent of Y
    • Independent⇒Correlation=0,  Correlation=0⇏IndependentIndependent\Rightarrow{Correlation=0}, \; Correlation=0\nRightarrow{Independent}
      证明: Use Counter-example
      Z∽N(0,1)Z\backsim{N(0,1)} and Cor(Z,Z2)=E(Z⋅Z2)−E(Z)E(Z2)=0−0=0Cor(Z, Z^2)=\mathbb{E}(Z\cdot{Z^2})-\mathbb{E}(Z)\mathbb{E}(Z^2)=0-0=0
      But ZZ in not independent of Z2Z^2

6 Normal Distribution

6.1 PDF

  • X∽N(μ,σ2)X\backsim{N(\mu,\sigma^2)} (μ\mu:期望, σ2\sigma^2:方差)
f(x)=1σ2πe−12σ2(x−μ)2,  −∞<x<+∞f(x)=\frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{1}{2\sigma^2}(x-\mu)^2},\; -\infty<x<+\infty
  • 标准正态:X∽N(μ=0,σ2=1)X\backsim{N(\mu=0,\sigma^2=1)}
f(x)=12πe−12x2,  −∞<x<+∞f(x)=\frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}x^2},\; -\infty<x<+\infty
  • Properties
    • X, Y are normal, X+Y is normal
    • Cor(X,Y)=0Cor(X,Y)=0 and X, Y are normal, then X, Y are independent

整理注: 正态变量之和的正态性与零相关推出独立,需联合正态等附加条件;只有边缘分布正态不足以推出。

6.2 The 68-95-99.7 Rule (记住)

  • 68% of the observations fall within σ\sigma of the mean μ\mu
  • 95% of the observations fall within 2σ2\sigma of the mean μ\mu
  • 99.7% of the observations fall within 3σ3\sigma of the mean μ\mu

6.3 Standardizing and z-scores

  1. if x is an observation from a normal distribution that has mean μ\mu and standard deviation σ\sigma, the standardized value of x is
z=x−μσz=\frac{x-\mu}{\sigma} f(x)=1σ2πe−12σ2(x−μ)2=1σ2πe−12(x−μσ)2=1σ2πe−12z2 \boxed{ \begin{aligned} f(x) & = \frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{1}{2\sigma^2}(x-\mu)^2} \\ & = \frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{1}{2}(\frac{x-\mu}{\sigma})^2} \\ & = \frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{1}{2}z^2} \end{aligned} }

A standardized value is often called a z-score. If x is normal distribution with mean μ\mu and standard deviation σ\sigma, then z is a standard normal variable with mean 0 and standard deviation. 2. (Review CLT)
Let x1,x2,…,xnx_1,x_2,\ldots,x_n be n i.i.d(独立同分布,缩写为iid、 i.i.d.、IID)normal random variables each with mean μ\mu and standard deviation σ\sigma.
The sum of all of them ∑xi\sum{x_i} is also a normal with mean nμn\mu and standard deviation σn\sigma\sqrt{n}.
Why standard deviation σn\sigma\sqrt{n}?

  • X, Y are independent, Var(X+Y)=Var(X)+Var(Y)Var(X+Y)=Var(X)+Var(Y)
  • Variance = square of standard deviation
  1. The distribution of average xˉ=∑xin\bar{x}=\frac{\sum{x_i}}{n} is also normal with mean μ\mu and standard deviation σ/n\sigma/\sqrt{n}.
    Why standard deviation σ/n\sigma/\sqrt{n}?

    • Var(cX)=c2⋅Var(X),  c=constVar(cX)=c^2\cdot{Var(X)}, \; c=const

    The standardized score of the mean xˉ\bar{x} is

z=xˉ−μσ/nz=\frac{\bar{x}-\mu}{\sigma/\sqrt{n}}

The mean of this standardized random variable is 0 and standard deviation is 1.

整理参考资料