详解降维-样本均值&样本方差矩阵【白板推导系列笔记】

87 阅读1分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第6天,点击查看活动详情

X=(x1x2 xN)N×pT=(x1Tx2T xNT)=(x11x12 x1px21x22 x2p    xN1xN2 xNP)N×pxiRp,i=1,2,,N1N=(11 1)N×1 \begin{gathered} X=\begin{pmatrix} x_{1} & x_{2} & \cdots  & x_{N} \end{pmatrix}^{T}_{N \times p}=\begin{pmatrix} x_{1}^{T} \\ x_{2}^{T} \\ \vdots  \\ x_{N}^{T} \end{pmatrix}=\begin{pmatrix} x_{11} & x_{12} & \cdots &  x_{1p} \\ x_{21} & x_{22} & \cdots  & x_{2p} \\ \vdots  & \vdots  &  & \vdots  \\ x_{N1} & x_{N2} & \cdots  & x_{NP} \end{pmatrix}_{N \times p}\\ x_{i}\in \mathbb{R}^{p},i=1,2,\cdots ,N\\ 记1_{N}=\begin{pmatrix}1 \\ 1 \\ \vdots  \\ 1\end{pmatrix}_{N \times 1} \end{gathered}

对于样本均值

xˉ=1Ni=1Nxi=1N(x1x2 xN)(11 1)N×1=1NXT1N \begin{aligned} \bar{x}&=\frac{1}{N}\sum\limits_{i=1}^{N}x_{i}\\ &=\frac{1}{N}\begin{pmatrix} x_{1} & x_{2} & \cdots  & x_{N} \end{pmatrix}\begin{pmatrix}1 \\ 1 \\ \vdots  \\ 1\end{pmatrix}_{N \times 1}\\ &=\frac{1}{N}X^{T}1_{N} \end{aligned}

对于样本方差

S=1Ni=1N(xixˉ)(xixˉ)T \begin{aligned} S&=\frac{1}{N}\sum\limits_{i=1}^{N}(x_{i}-\bar{x})(x_{i}-\bar{x})^{T} \end{aligned}

对于i=1N(xixˉ)\sum\limits_{i=1}^{N}(x_{i}-\bar{x})

i=1N(xixˉ)=(x1xˉx2xˉ xNxˉ)=(x1x2 xN)(xˉxˉ xˉ)=XTxˉ(11 1)=XTxˉ1NT=XT1NXT1N1NT=XT(IN1N1N1NT) \begin{aligned} \sum\limits_{i=1}^{N}(x_{i}-\bar{x})&=\begin{pmatrix} x_{1}-\bar{x} & x_{2}-\bar{x} & \cdots  & x_{N}-\bar{x} \end{pmatrix}\\ &=\begin{pmatrix} x_{1} & x_{2} & \cdots  & x_{N} \end{pmatrix}-\begin{pmatrix} \bar{x} & \bar{x} & \cdots  & \bar{x} \end{pmatrix}\\ &=X^{T}-\bar{x}\begin{pmatrix}1 & 1 & \cdots  & 1\end{pmatrix}\\ &=X^{T}-\bar{x}1_{N}^{T}\\ &=X^{T}- \frac{1}{N}X^{T}1_{N}1_{N}^{T}\\ &=X^{T}\left(\mathbb{I}_{N}- \frac{1}{N}1_{N}1_{N}^{T}\right)\\ \end{aligned}

带回原式

S=1N(x1xˉx2xˉ xNxˉ)((x1xˉ)T(x2xˉ)T (xNxˉ)T)=1NXT(IN1N1N1NT)(IN1N1N1NT)TX \begin{aligned} S&=\frac{1}{N}\begin{pmatrix} x_{1}-\bar{x} & x_{2}-\bar{x} & \cdots  & x_{N}-\bar{x} \end{pmatrix}\begin{pmatrix} (x_{1}-\bar{x})^{T} \\ (x_{2}-\bar{x})^{T} \\ \vdots  \\ (x_{N}-\bar{x})^{T} \end{pmatrix}\\ &=\frac{1}{N}X^{T}\left(\mathbb{I}_{N}- \frac{1}{N}1_{N}1_{N}^{T}\right)\cdot (\mathbb{I}_{N}- \frac{1}{N}1_{N}1_{N}^{T})^{T}X\\ \end{aligned}

H=IN1N1N1NT\begin{aligned} \mathbb{H}=\mathbb{I}_{N}- \frac{1}{N}1_{N}1_{N}^{T}\end{aligned}H\mathbb{H}也被称为中心矩阵),上式为

S=1NXT(IN1N1N1NT)(IN1N1N1NT)TX=1NXTHHX \begin{aligned} S&=\frac{1}{N}X^{T}\left(\mathbb{I}_{N}- \frac{1}{N}1_{N}1_{N}^{T}\right)\cdot (\mathbb{I}_{N}- \frac{1}{N}1_{N}1_{N}^{T})^{T}X\\ &=\frac{1}{N}X^{T}\mathbb{H}\cdot \mathbb{H}X \end{aligned}

对于HT\mathbb{H}^{T}

HT=(IN1N1N1NT)T=IN1N1N1NT=H \begin{aligned} \mathbb{H}^{T}&=(\mathbb{I}_{N}- \frac{1}{N}1_{N}1_{N}^{T})^{T}\\ &=\mathbb{I}_{N}- \frac{1}{N}1_{N}1_{N}^{T}\\ &=\mathbb{H} \end{aligned}

对于H2\mathbb{H}^{2}

H2=HH=(IN1N1N1NT)(IN1N1N1NT)=IN2N1N1NT+1N21N1NT1N1NT \begin{aligned} \mathbb{H}^{2}&=\mathbb{H} \cdot \mathbb{H}\\ &=\left(\mathbb{I}_{N}- \frac{1}{N}1_{N}1_{N}^{T}\right)\left(\mathbb{I}_{N}- \frac{1}{N}1_{N}1_{N}^{T}\right)\\ &=\mathbb{I}_{N}- \frac{2}{N}1_{N}1_{N}^{T}+ \frac{1}{N^{2}}1_{N}1_{N}^{T}1_{N}1_{N}^{T} \end{aligned}

对于1N1NT1_{N}1_{N}^{T}

1N1NT=(1 1)(1 1)=(1 1   1 1)1N1NT1N1NT=(1 1   1 1)(1 1   1 1)=(N N   N N) \begin{aligned} 1_{N}1_{N}^{T}&=\begin{pmatrix} 1 \\ \vdots  \\ 1 \end{pmatrix}\begin{pmatrix} 1 & \cdots  & 1 \end{pmatrix}=\begin{pmatrix} 1 & \cdots  & 1 \\ \vdots  &  & \vdots  \\ 1 & \cdots  & 1 \end{pmatrix}\\ 1_{N}1_{N}^{T}1_{N}1_{N}^{T}&=\begin{pmatrix} 1 & \cdots  & 1 \\ \vdots  &  & \vdots  \\ 1 & \cdots  & 1 \end{pmatrix}\begin{pmatrix} 1 & \cdots  & 1 \\ \vdots  &  & \vdots  \\ 1 & \cdots  & 1 \end{pmatrix}\\ &=\begin{pmatrix} N & \cdots  & N \\ \vdots  &  & \vdots  \\ N & \cdots  & N \end{pmatrix} \end{aligned}

带回H2\mathbb{H}^{2}

H2=IN2N1N1NT+1N21N1NT1N1NT=IN2N(1 1   1 1)+1N2(N N   N N)=IN2N(1 1   1 1)+1N(1 1   1 1)=IN1N(1 1   1 1)=IN1N1N1NT=H \begin{aligned} \mathbb{H}^{2}&=\mathbb{I}_{N}- \frac{2}{N}1_{N}1_{N}^{T}+ \frac{1}{N^{2}}1_{N}1_{N}^{T}1_{N}1_{N}^{T}\\ &=\mathbb{I}_{N}- \frac{2}{N}\begin{pmatrix} 1 & \cdots  & 1 \\ \vdots  &  & \vdots  \\ 1 & \cdots  & 1 \end{pmatrix}+ \frac{1}{N^{2}}\begin{pmatrix} N & \cdots  & N \\ \vdots  &  & \vdots  \\ N & \cdots  & N \end{pmatrix}\\ &=\mathbb{I}_{N}- \frac{2}{N}\begin{pmatrix} 1 & \cdots  & 1 \\ \vdots  &  & \vdots  \\ 1 & \cdots  & 1 \end{pmatrix}+ \frac{1}{N}\begin{pmatrix} 1 & \cdots  & 1 \\ \vdots  &  & \vdots  \\ 1 & \cdots  & 1 \end{pmatrix}\\ &=\mathbb{I}_{N}- \frac{1}{N}\begin{pmatrix} 1 & \cdots  & 1 \\ \vdots  &  & \vdots  \\ 1 & \cdots  & 1 \end{pmatrix}\\ &=\mathbb{I}_{N}- \frac{1}{N}1_{N}1_{N}^{T}\\ &=\mathbb{H} \end{aligned}

因此有Hn=H\mathbb{H}^{n}=\mathbb{H},带回SS

S=1NXTHHX=1NXTHX \begin{aligned} S&=\frac{1}{N}X^{T}\mathbb{H}\cdot \mathbb{H}X\\ &=\frac{1}{N}X^{T}\mathbb{H}X \end{aligned}

这里中心矩阵H\mathbb{H}的几何意义是,对于一个数据集XXXHX \mathbb{H}可以认为是将数据集平移到坐标轴原点,H\mathbb{H}就是这个起到平移作用的矩阵