Principal Component Analysis (PCA), or the Karhunen–Loève transform (KLT), is a technique with two important applications in data analysis:
There are likewise two formulations of the definition of PCA:
A practical example of dimensionality reduction is the equation of a hyperplane in dimensions: there is a basis of the space in which the equation of the hyperplane can be reduced to
dimensions without loss of information, thereby reducing the dimensionality of the problem by one.
are stored in the rows2.2 of the matrix of size
, which therefore stores
random vectors of dimension
and with
.
Each row corresponds to a different observation , and the distribution of these observations must have zero mean, at least empirically.
Assuming that the points have zero mean (which can always be achieved by simply subtracting the centroid), the covariance matrix of the observations is given by
| (2.69) |
If the input data are correlated, the covariance matrix
is not diagonal.
The goal of PCA is to find an optimal transformation that transforms the data from correlated to uncorrelated
| (2.70) |
and orders them according to their information content, so that selecting a subset of the basis vectors can reduce the dimensionality of the problem.
If there is an orthonormal basis in which the covariance matrix
is diagonal, then the axes of this new basis are called the principal components of
(or of the distribution of
).
A covariance matrix with all off-diagonal elements equal to zero means that the events are uncorrelated in this new basis.
This transformation can be found by solving an eigenvalue problem: it can be shown that the diagonal elements are the eigenvalues of
, and that the variances of the projections of the vector
onto the principal components are equal to these eigenvalues:
where is the matrix of eigenvectors (an orthogonal matrix such that
) and
is the diagonal matrix of eigenvalues, ordered as
.
There are two ways to obtain this result.
Since
is a real, symmetric, positive semidefinite matrix, it can be decomposed as
This is called the spectral decomposition, where is the orthonormal eigenvector matrix and
is the diagonal matrix of eigenvalues. Since the matrix
is positive semidefinite, all its eigenvalues are nonnegative.
However, this technique requires explicitly computing
.
For a rectangular matrix , the singular value decomposition (SVD) provides the eigenvectors of
in a numerically stable way, and the corresponding eigenvalues are given by the squares of the singular values.
The SVD is therefore the standard method for computing the principal components.
The matrix of observations can be decomposed using the SVD as
using the Economy/Compact SVD, where contains the left singular vectors,
contains the singular values of
, and
contains the right singular vectors.
Note that with the SVD, there is no need to explicitly compute the covariance matrix
. It can be obtained later using
| (2.73) |
Comparing this relation with Equation (2.72) gives
| (2.74) |
Recall the following properties of eigenvalues and singular values:
Another important property of the SVD is
which gives the best rank- approximation of the matrix
in the Frobenius norm.
Together with the fact that the SVD returns the singular values in descending order, this property allows a matrix to be approximated by one of lower rank.
By selecting the eigenvectors associated with the largest eigenvalues, we can construct a matrix
whose columns form an orthonormal basis for the reduced space. The projection of a vector
onto this subspace is
with
The vector is a lower-dimensional representation of the data that preserves most of the variance in the system.