PCA

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 $d$ dimensions: there is a basis of the space in which the equation of the hyperplane can be reduced to $d-1$ dimensions without loss of information, thereby reducing the dimensionality of the problem by one.

Figure 2.2: Principal Components.
Image fig_pca

are stored in the rows2.2 of the matrix $\mathbf{X}$ of size $n \times d$, which therefore stores $n$ random vectors of dimension $d$ and with $n > d$.

Each row corresponds to a different observation $\mathbf{x}_i$, 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


\begin{displaymath}
\boldsymbol\Sigma
=
E(\mathbf{x}\mathbf{x}^{\top})
\approx
\frac{1}{n}
\mathbf{X}^{\top}\mathbf{X}
\end{displaymath} (2.69)

If the input data $\mathbf {x}$ are correlated, the covariance matrix $\boldsymbol\Sigma$ is not diagonal.

The goal of PCA is to find an optimal transformation $\mathbf{V}$ that transforms the data from correlated to uncorrelated


\begin{displaymath}
\mathbf{y}
=
\mathbf{V}^{\top}\mathbf{x}
\end{displaymath} (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 $\mathbf{V}$ in which the covariance matrix $\boldsymbol\Sigma$ is diagonal, then the axes of this new basis are called the principal components of $\boldsymbol\Sigma$ (or of the distribution of $\mathbf {x}$). 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 $\boldsymbol\Sigma$, and that the variances of the projections of the vector $\mathbf {x}$ onto the principal components are equal to these eigenvalues:


\begin{displaymath}
\boldsymbol\Sigma \mathbf{V}
=
\mathbf{V}\boldsymbol\Delta
\end{displaymath} (2.71)

where $\mathbf{V}$ is the matrix of eigenvectors (an orthogonal matrix such that $\mathbf{V}\mathbf{V}^{\top}=\mathbf{I}$) and $\boldsymbol\Delta$ is the diagonal matrix of eigenvalues, ordered as $\lambda_1 \ge \ldots \ge \lambda_d$.

There are two ways to obtain this result.

Since $\boldsymbol\Sigma$ is a real, symmetric, positive semidefinite matrix, it can be decomposed as


\begin{displaymath}
\boldsymbol\Sigma
=
\mathbf{V}\boldsymbol\Delta\mathbf{V}^{\top}
\end{displaymath} (2.72)

This is called the spectral decomposition, where $\mathbf{V}$ is the orthonormal eigenvector matrix and $\boldsymbol\Delta$ is the diagonal matrix of eigenvalues. Since the matrix $\boldsymbol\Sigma$ is positive semidefinite, all its eigenvalues are nonnegative.

However, this technique requires explicitly computing $\boldsymbol\Sigma$.

For a rectangular matrix $\mathbf{X}$, the singular value decomposition (SVD) provides the eigenvectors of $\mathbf{X}^{\top}\mathbf{X}$ 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 $\mathbf{X}$ can be decomposed using the SVD as


\begin{displaymath}
\mathbf{X}
=
\mathbf{U}\mathbf{S}\mathbf{V}^{\top}
\end{displaymath}

using the Economy/Compact SVD, where $\mathbf{U}$ contains the left singular vectors, $\mathbf{S}$ contains the singular values of $\mathbf{X}$, and $\mathbf{V}$ contains the right singular vectors.

Note that with the SVD, there is no need to explicitly compute the covariance matrix $\boldsymbol\Sigma$. It can be obtained later using


\begin{displaymath}
\boldsymbol\Sigma
=
\frac{1}{n}\mathbf{X}^{\top}\mathbf{X}
=
\frac{1}{n}\mathbf{V}\mathbf{S}^{2}\mathbf{V}^{\top}
\end{displaymath} (2.73)

Comparing this relation with Equation (2.72) gives


\begin{displaymath}
\boldsymbol\Delta
=
\frac{1}{n}\mathbf{S}^{2}.
\end{displaymath} (2.74)

Recall the following properties of eigenvalues and singular values:

Another important property of the SVD is


\begin{displaymath}
\mathbf{X}^{(l)}
=
\sum_{i=1}^{l}
\sigma_i
\mathbf{u}_i
\mathbf{v}_i^{\top}
\end{displaymath} (2.75)

which gives the best rank-$l$ approximation of the matrix $\mathbf{X}$ 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


\begin{displaymath}
\tilde{\mathbf V}
\in
\mathbb{R}^{d\times m}
\end{displaymath}

whose columns form an orthonormal basis for the reduced space. The projection of a vector


\begin{displaymath}
\mathbf x \in \mathbb{R}^{d}
\end{displaymath}

onto this subspace is


\begin{displaymath}
\mathbf y
=
\tilde{\mathbf V}^{\top}\mathbf x
\end{displaymath}

with


\begin{displaymath}
\mathbf y \in \mathbb{R}^{m}.
\end{displaymath}

The vector $\mathbf y$ is a lower-dimensional representation of the data that preserves most of the variance in the system.

Figure 2.3: Example of the first 10 eigenvectors $24 \times 48$ extracted from the Daimler-DB pedestrian dataset
Image fig_pca_ped



Footnotes

...rows2.2
This document uses the row-wise convention: the literature uses both row-wise and column-wise representations of data, so the terminology may differ and refer to $\mathbf{U}$ rather than $\mathbf{V}$, or vice versa.
Paolo medici
2026-10-19