主成分分析
在多元统计分析中,主成分分析(英语:Principal components analysis,PCA)是一種分析、簡化數據集的技術。主成分分析经常用减少数据集的维数,同时保持数据集的对方差贡献最大的特征。这是通过保留低阶主成分,忽略高阶主成分做到的。这样低阶成分往往能够保留住数据的最重要方面。但是,这也不是一定的,要视具体应用而定。由于主成分分析依赖所给数据,所以数据的准确性对分析结果影响很大。
主成分分析由卡爾·皮爾遜於1901年發明[1],用於分析數據及建立數理模型。其方法主要是通過對共變異數矩陣進行特征分解[2],以得出數據的主成分(即特征向量)與它們的權值(即特征值[3])。PCA是最簡單的以特征量分析多元統計分布的方法。其結果可以理解為對原數據中的方差做出解釋:哪一個方向上的數據值對方差的影響最大?換而言之,PCA提供了一種降低數據維度的有效辦法;如果分析者在原數據中除掉最小的特征值所對應的成分,那麼所得的低維度數據必定是最優化的(也即,這樣降低維度必定是失去訊息最少的方法)。主成分分析在分析複雜數據時尤為有用,比如人臉識別。
PCA是最简单的以特征量分析多元统计分布的方法。通常情况下,这种运算可以被看作是揭露数据的内部结构,从而更好的解释数据的变量的方法。如果一个多元数据集能够在一个高维数据空间坐标系中被显现出来,那么PCA就能够提供一幅比较低维度的图像,这副图像即为在讯息最多的点上原对象的一个‘投影’。这样就可以利用少量的主成分使得数据的维度降低了。
PCA跟因子分析密切相关,并且已经有很多混合这两种分析的统计包。而真实要素分析则是假定底层结构,求得微小差异矩阵的特征向量。
目录 |
数学定义 [编辑]
PCA的数学定义是:一个正交化线性变换,把数据变换到一个新的坐标系统中,使得这一数据的任何投影的第一大方差在第一个坐标(称为第一主成分)上,第二大方差在第二个坐标(第二主成分)上,依次类推[4]。
定义一个n × m的矩阵, XT为去平均值(以平均值为中心移动至原点)的数据,其行为数据样本,列为数据类别(注意,这里定义的是XT 而不是X)。则X的奇异值分解为X = WΣVT,其中m × m矩阵W是XXT的本征矢量矩阵, Σ是m × n的非负矩形对角矩阵,V是n × n的XTX的本征矢量矩阵。据此,
当 m < n − 1时,V 在通常情况下不是唯一定义的,而Y 则是唯一定义的。W 是一个正交矩阵,YT是XT的转置,且YT的第一列由第一主成分组成,第二列由第二主成分组成,依此类推。
为了得到一种降低数据维度的有效办法,我们可以把 X 映射到一个只应用前面L个向量的低维空间中去,WL:
where
with
the
rectangular identity matrix.
X 的单向量矩阵W相当于协方差矩阵的本征矢量 C = X XT,
在欧几里得空间给定一组点数,第一主成分对应于通过多维空间平均点的一条线,同时保证各个点到这条直线距离的平方和最小。去除掉第一主成分后,用同样的方法得到第二主成分。依此类推。在Σ中的奇异值均为矩阵 XXT的本征值的平方根。每一个本征值都与跟它们相关的方差是成正比的,而且所有本征值的总和等于所有点到它们的多维空间平均点距离的平方和。PCA提供了一种降低维度的有效办法,本质上,它利用正交变换将围绕平均点的点集中尽可能多的变量投影到第一维中去,因此,降低维度必定是失去讯息最少的方法。PCA具有保持子空间拥有最大方差的最优正交变换的特性。然而,当与离散余弦变换相比时,它需要更大的计算需求代价。非线性降维技术相对于PCA来说则需要更高的计算要求。
PCA对变量的缩放很敏感。如果我们只有两个变量,而且它们具有相同的样本方差,并且成正相关,那么PCA将涉及两个变量的主成分的旋转。但是,如果把第一个变量的所有值都乘以100,那么第一主成分就几乎和这个变量一样,另一个变量只提供了很小的贡献,第二主成分也将和第二个原始变量几乎一致。这就意味着当不同的变量代表不同的单位(如温度和质量)时,PCA是一种比较武断的分析方法。但是在Pearson的题为 "On Lines and Planes of Closest Fit to Systems of Points in Space"的原始文件里,是假设在欧几里得空间里不考虑这些。一种使PCA不那么武断是方法是使用变量缩放以得到单位方差。
讨论 [编辑]
通常,为了确保第一主成分描述的是最大方差的方向,我们会使用平均减法进行主成分分析。如果不执行平均减法,第一主成分有可能或多或少的对应于数据的平均值。另外,为了找到近似数据的最小均方误差,我们必须选取一个零均值[5]。
假设零经验均值,数据集 X 的主成分w1可以被定义为:
为了得到第 k个主成分,必须先从X中减去前面的
个主成分:
然后把求得的第k个主成分带入数据集,得到新的数据集,继续寻找主成分。
PCA相当于在气象学中使用的经验正交函数(EOF),同时也类似于一个线性隐层神经网络。 隐含层 K 个神经元的权重向量收敛后,将形成一个由前 K 个主成分跨越空间的基础。但是与PCA不同的是,这种技术并不一定会产生正交向量。
PCA是一种很流行且主要的的模式识别技术。然而,它并不能最优化类别可分离性[6] 。另一种不考虑这一点的方法是线性判别分析。
符号和缩写表 [编辑]
| Symbol符号 | Meaning意义 | Dimensions尺寸 | Indices指数 |
|---|---|---|---|
![]() |
由所有数据向量集组成的数据矩阵,一列代表一个向量 | ![]() |
![]() ![]() |
![]() |
数据集中列向量的个数 | ![]() |
标量 |
![]() |
每个列向量的元素个数 | ![]() |
标量 |
![]() |
子空间的维数, ![]() |
![]() |
标量 |
![]() |
经验均值向量 | ![]() |
![]() |
![]() |
经验标准方差向量 | ![]() |
![]() |
![]() |
所有的单位向量 | ![]() |
![]() |
![]() |
对均值的偏离向量 | ![]() |
![]() ![]() |
![]() |
Z-分数,利用均值和标准差计算得到 | ![]() |
![]() ![]() |
![]() |
协方差矩阵 | ![]() |
![]() ![]() |
![]() |
相关矩阵 | ![]() |
![]() ![]() |
![]() |
C的所有特征向量集 | ![]() |
![]() ![]() |
![]() |
主对角线为特征值的对角矩阵 | ![]() |
![]() ![]() |
![]() |
基向量矩阵 | ![]() |
![]() ![]() |
![]() |
X 和W矩阵的投影矩阵 | ![]() |
![]() ![]() |
主成分分析的属性和限制 [编辑]
如上所述,主成分分析的结果取决于变量的缩放。
主成分分析的适用性受到由它的派生物产生的某些假设[7] 的限制。
使用统计方法计算PCA [编辑]
以下是使用统计方法计算PCA的详细说明。但是请注意,如果利用奇异值分解(使用标准的软件)效果会更好。
我们的目标是把一个给定的具有 M 维的数据集X 变换成具有较小维度 L的数据集Y。现在要求的就是矩阵Y,Y是矩阵X Karhunen–Loève变换。:
组织数据集 [编辑]
假设有一组 M 个变量的观察数据,我们的目的是减少数据,使得能够用L 个向量来描述每个观察值,L < M。进一步假设,该数据被整理成一组具有N个向量的数据集,其中每个向量都代表M 个变量的单一观察数据。
为列向量,其中每个列向量有M 行。
- 将列向量放入M × N的单矩阵X 里。
计算经验均值 [编辑]
- 对每一维m = 1, ..., M计算经验均值
- 将计算得到的均值放入一个 M × 1维的经验均值向量u中
计算平均偏差 [编辑]
对于在最大限度地减少近似数据的均方误差的基础上找到一个主成分来说,均值减去法是该解决方案的不可或缺的组成部分[8] 。因此,我们继续如下步骤:
- 从数据矩阵X的每一列中减去经验均值向量 u
- 将平均减去过的数据存储在M × N矩阵B中
-

- where h is a 1 × N row vector of all 1s:
其中h是一个全 1s:的1 × N 的行向量
求协方差矩阵 [编辑]
- 从矩阵B 中找到M × M 的经验协方差矩阵C
其中
为期望值
是最外层运算符
是共轭转置运算符。
请注意,如果B完全由实数组成,那么共轭转置与正常的转置一样。
查找协方差矩阵的特征值和特征向量 [编辑]
- 计算矩阵V 的特征向量
- 其中,D 是C的特征值对角矩阵,这一步通常会涉及到使用基于计算机的计算特征值和特征向量的算法。在很多矩阵代数系统中这些算法都是现成可用的,如R语言,MATLAB,[9][10] Mathematica,[11] SciPy, IDL(交互式数据语言), 或者GNU Octave以及OpenCV。
- 矩阵D为M × M的对角矩阵
- 各个特征值和特征向量都是配对的,m个特征值对应m个特征向量。
软件的源代码 [编辑]
- Cornell Spectrum Imager - An open-source toolset built on ImageJ. Enables quick easy PCA analysis for 3D datacubes.
- imDEV Free Excel addin to calculate principal components using R package pcaMethods.
- "ViSta: The Visual Statistics System" a free software that provides principal components analysis, simple and multiple correspondence analysis.
- "Spectramap" is software to create a biplot using principal components analysis, correspondence analysis or spectral map analysis.
- XLSTAT is a statistical and multivariate analysis software including Principal Component Analysis among other multivariate tools.
- FinMath, a .NET numerical library containing an implementation of PCA.
- The Unscrambler is a multivariate analysis software enabling Principal Component Analysis (PCA) with PCA Projection.
- Computer Vision Library
- In the MATLAB Statistics Toolbox, the functions
princompandwmspcagive the principal components, while the functionpcaresgives the residuals and reconstructed matrix for a low-rank PCA approximation. Here is a link to a MATLAB implementation of PCAPcaPress. - In the NAG Library, principal components analysis is implemented via the
g03aaroutine (available in both the Fortran[12] and the C[13] versions of the Library). - NMath, a proprietary numerical library containing PCA for the .NET Framework.
- in Octave, a free software computational environment mostly compatible with MATLAB, the function
princompgives the principal component. - in the free statistical package R, the functions
princompandprcompcan be used for principal component analysis;prcompuses singular value decomposition which generally gives better numerical accuracy. Recently there has been an explosion in implementations of principal component analysis in various R packages, generally in packages for specific purposes. For a more complete list, see here: [1]. - In XLMiner, the Principal Components tab can be used for principal component analysis.
- In IDL, the principal components can be calculated using the function
pcomp. - Weka computes principal components (javadoc).
- Software for analyzing multivariate data with instant response using PCA
- Orange (software) supports PCA through its Linear Projection widget.
- A version of PCA adapted for population genetics analysis can be found in the suite EIGENSOFT.
- PCA can also be performed by the statistical software Partek Genomics Suite, developed by Partek.
参见 [编辑]
- Multilinear PCA
- Correspondence analysis
- Eigenface
- Exploratory factor analysis (Wikiversity)
- Geometric data analysis
- Factorial code
- Independent component analysis
- Kernel PCA
- Matrix decomposition
- Nonlinear dimensionality reduction
- Oja's rule
- Point distribution model (PCA applied to morphometry and computer vision)
- Principal component regression
- Principal component analysis (Wikibooks)
- Singular spectrum analysis
- Singular value decomposition
- Sparse PCA
- Transform coding
- Weighted least squares
- Dynamic mode decomposition
- Low-rank approximation
注释 [编辑]
- ^ Pearson, K.. On Lines and Planes of Closest Fit to Systems of Points in Space (PDF). Philosophical Magazine. 1901, 2 (6): 559–572.
- ^ Abdi. H., & Williams, L.J.. Principal component analysis.. Wiley Interdisciplinary Reviews: Computational Statistics,. 2010, 2: 433–459.
- ^ Shaw P.J.A. (2003) Multivariate statistics for the Environmental Sciences, Hodder-Arnold. ISBN 0-3408-0763-6.[页码请求]
- ^ Jolliffe I.T. Principal Component Analysis, Series: Springer Series in Statistics, 2nd ed., Springer, NY, 2002, XXIX, 487 p. 28 illus. ISBN 978-0-387-95442-4
- ^ A. A. Miranda, Y. A. Le Borgne, and G. Bontempi. New Routes from Minimal Approximation Error to Principal Components, Volume 27, Number 3 / June, 2008, Neural Processing Letters, Springer
- ^ Fukunaga, Keinosuke. Introduction to Statistical Pattern Recognition. Elsevier. 1990. ISBN 0122698517.
- ^ Jonathon Shlens, A Tutorial on Principal Component Analysis.
- ^ A.A. Miranda, Y.-A. Le Borgne, and G. Bontempi. New Routes from Minimal Approximation Error to Principal Components, Volume 27, Number 3 / June, 2008, Neural Processing Letters, Springer
- ^ eig function Matlab documentation
- ^ MATLAB PCA-based Face recognition software
- ^ Eigenvalues function Mathematica documentation
- ^ The Numerical Algorithms Group. NAG Library Routine Document: nagf_mv_prin_comp (g03aaf). NAG Library Manual, Mark 23. [2012-02-16].
- ^ The Numerical Algorithms Group. NAG Library Routine Document: nag_mv_prin_comp (g03aac). NAG Library Manual, Mark 9. [2012-02-16].
参考 [编辑]
- Jolliffe, I. T. Principal Component Analysis. Springer-Verlag. 1986: 487. doi:10.1007/b98835. ISBN 978-0-387-95442-4.
外部链接 [编辑]
| 维基共享资源中相关的多媒体资源:主成分分析 |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||

where
with
the
rectangular identity matrix.



![\mathbf{X} = \{ X[m,n] \}](http://upload.wikimedia.org/math/f/8/6/f867e7c98e184b05ed01eedf48d48da5.png)








![\mathbf{u} = \{ u[m] \}](http://upload.wikimedia.org/math/5/c/8/5c8208a0df7d9bf4da7d597b1870f23d.png)

![\mathbf{s} = \{ s[m] \}](http://upload.wikimedia.org/math/c/6/7/c676f10f15d0881db172967871693572.png)
![\mathbf{h} = \{ h[n] \}](http://upload.wikimedia.org/math/0/5/c/05c290900324b15ef4123a2293a2c544.png)

![\mathbf{B} = \{ B[m,n] \}](http://upload.wikimedia.org/math/3/b/0/3b00e80fb5f767ceaba11c14ffbe7ffb.png)
![\mathbf{Z} = \{ Z[m,n] \}](http://upload.wikimedia.org/math/4/e/3/4e3dbd4fb1b5ef217ba716a1a90d2511.png)
![\mathbf{C} = \{ C[p,q] \}](http://upload.wikimedia.org/math/a/2/a/a2ae59fecd9a30529c7ab8260e534f1a.png)



![\mathbf{R} = \{ R[p,q] \}](http://upload.wikimedia.org/math/0/4/2/042cc0a47cdc31cb96cd0720c0ac51b2.png)
![\mathbf{V} = \{ V[p,q] \}](http://upload.wikimedia.org/math/0/5/f/05f86efc393e12e96b879e1b48e9fb4f.png)
![\mathbf{D} = \{ D[p,q] \}](http://upload.wikimedia.org/math/a/c/d/acdc2b89fb7f17e8ba1abbda6f4f0a01.png)
![\mathbf{W} = \{ W[p,q] \}](http://upload.wikimedia.org/math/0/6/1/0616329127868d5b6c7a63513a096761.png)


![\mathbf{Y} = \{ Y[m,n] \}](http://upload.wikimedia.org/math/9/3/f/93ff4f2a52b9c57cb8d4d718c2ec8377.png)


为列向量,其中每个列向量有M 行。![u[m] = {1 \over N} \sum_{n=1}^N X[m,n]](http://upload.wikimedia.org/math/8/9/5/8957f38829f7b6c873a6248176f16b58.png)

![h[n] = 1 \, \qquad \qquad \text{for } n = 1, \ldots, N](http://upload.wikimedia.org/math/2/e/a/2eab23221256ff7f9520579f8fe04a8e.png)
![\mathbf{C} = \mathbb{ E } \left[ \mathbf{B} \otimes \mathbf{B} \right] = \mathbb{ E } \left[ \mathbf{B} \cdot \mathbf{B}^{*} \right] = { 1 \over N } \sum_{} \mathbf{B} \cdot \mathbf{B}^{*}](http://upload.wikimedia.org/math/7/7/1/7710366946cc46e2032d40a41985c8e5.png)
