Principal component analysis
In statistics, principal components analysis (PCA), Pearson, 1901, is a technique that can be used to simplify a dataset; more formally it is a linear transformation that chooses a new coordinate system for the data set such that the greatest variance by any projection of the data set comes to lie on the first axis (then called the first principal component), the second greatest variance on the second axis, and so on. PCA can be used for reducing dimensionality in a dataset while retaining those characteristics of the dataset that contribute most to its variance by eliminating the later principal components (by a more or less heuristic decision). These characteristics may be the "most important", but this is not necessarily the case, depending on the application.
PCA is also called the Karhunen-Loève transform (named after Kari Karhunen and Michel Loève) or the Hotelling transform (in honor of Harold Hotelling). PCA has the distinction of being the optimal linear transformation for keeping the subspace that has largest variance. This advantage, however, comes at the price of greater computational requirement if compared, for example, to the discrete cosine transform. Unlike other linear transforms, the PCA does not have a fixed set of basis vectors. Its basis vectors depend on the data set.
Assuming zero empirical mean (the empirical mean of the distribution has been subtracted away from the data set), the principal component w1 of a dataset x can be defined as:
(See arg max for the notation.) With the first components, the -th component can be found by subtracting the first principal components from x:
and by substituting this as the new dataset to find a principal component in
- .
A simpler way to calculate the components wi uses the empirical covariance matrix of x, the measurement vector. By finding the eigenvalues and eigenvectors of the covariance matrix, we find that the eigenvectors with the largest eigenvalues correspond to the dimensions that have the strongest correlation in the dataset. The original measurements are finally projected onto the reduced vector space. Note that the eigenvectors X are actually the columns of the matrix V, where X=ULV′ is the singular value decomposition of X.
PCA is equivalent to empirical orthogonal functions (EOF).
PCA is a popular technique in pattern recognition. However, PCA is not optimized for class separability. An alternative is the linear discriminant analysis, which does take this into account. PCA optimally minimizes reconstruction error under the L2 norm.
Algorithm details
Table of symbols and abbreviations
Symbol | Meaning | Dimensions | Indices |
---|---|---|---|
data matrix, consisting of the set of all data vectors, one vector per column | | ||
the number of column vectors in the data set | scalar | ||
the number of elements in each column vector | scalar | ||
the number of dimensions in the dimensionally reduced subspace, | scalar | ||
vector of empirical means, one mean for each row m of the data matrix | |||
vector of empirical standard deviations, one standard deviation for each row m of the data matrix | |||
vector of all 1's | |||
deviations from the mean of each row m of the data matrix | | ||
z-scores, computed using the mean and standard deviation for each row m of the data matrix | | ||
covariance matrix | | ||
correlation matrix | | ||
matrix consisting of the set of all eigenvectors of C, one eigenvector per column | | ||
diagonal matrix consisting of the set of all eigenvalues of C along its principal diagonal, and 0 for all other elements | | ||
matrix consisting of a subset of the eigenvectors of C, one eigenvector per column | |
Find the basis vectors
Following is a detailed description of PCA using the covariance method. Suppose you have N data vectors each length M, written as , and you want to project your data into a L dimensional subspace.
1. | Organize your data into column vectors, so you end up with an matrix, X. |
2. | Find the empirical mean along each dimension, so you end up with an empirical mean vector, u |
3. | Subtract the empirical mean vector u from each column of the data matrix X. Store mean-subtracted data matrix in Y. |
where h is a 1 x N vector of all 1's:
| |
4. | Find the empirical covariance matrix C from matrix Y:
|
5. | Create an empirical standard deviation vector s from the square root of each element along the main diagonal of the covariance matrix C:
|
6. | Compute and sort by decreasing eigenvalue D, the eigenvectors V of the covariance matrix C. |
7. | Save the mean vector u. Save the first L columns of V as the matrix W, where
|
Observation
Using the covariance matrix C and the standard deviation vector s, compute the correlation matrix R as:
- .
The matrix R is symmetric (like the covariance matrix), its values are between -1 and 1, and the sum of the elements along the main diagonal is N. In other words, the trace of matrix R is N:
When the different dimensions of the input data have different measuring units, by using the matrix C we are computing linear combinations of data of different scales; thus using the normalized matrix R makes more sense.
In that case steps 6 and 7 become:
6. Compute and sort by decreasing eigenvalue, the eigenvectors V of R.
7. Save the mean vector u and the standard deviation vector s. Save the first L columns of V as the matrix W. where
- .
Projecting new data
Suppose you have a M×1 data vector D. Then the k×1 projected vector is v = PT(D − u).
If the correlation matrix R has been used instead of the covariance matrix C, the elements of the input vector should be normalized: . Then the projected vector is .
Derivation of PCA using the covariance method
Let X be a d-dimensional random vector expressed as column vector. Without loss of generality, assume X has zero empirical mean. We want to find a orthonormal projection matrix P such that
with the constraint that
- is a diagonal matrix and .
By substitution, and matrix algebra, we obtain:
- .
We now have:
- .
Rewrite P as d column vectors, so
and as:
- .
Substituting into equation above, we obtain:
- .
Notice that in , Pi is an eigenvector of X′s covariance matrix. Therefore, by finding the eigenvectors of X′s covariance matrix, we find a projection matrix P that satisfies the original constraints.
Correspondence analysis
Correspondence analysis is conceptually similar to PCA, but scales the data (which must be positive) so that rows and columns are treated equivalently. It is traditionally applied to contingency tables where Pearson's chi-square test has shown a relationship between rows and columns.
References
See also
- eigenface
- transform coding
- independent components analysis
- singular value decomposition
- factor analysis