1. Home
  2. Explore
  3. Mathematics
  4. Principal Component Analysis

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Principal Component Analysis

Principal Component Analysis, Matrix Norms, and Low-Rank Approximation

The SVD as a way to represent a matrix

The singular value decomposition (SVD) expresses an m×nm \times nm×n matrix AAA as

A=UΣVT,A = U\Sigma V^T,A=UΣVT,

where UUU and VVV have orthonormal columns and Σ\SigmaΣ contains the singular values. The singular values are conventionally ordered from largest to smallest:

σ1≥σ2≥⋯≥σr>0,\sigma_1 \geq \sigma_2 \geq \cdots \geq \sigma_r > 0,σ1​≥σ2​≥⋯≥σr​>0,

where rrr is the rank of AAA.

Equivalently, the SVD writes AAA as a sum of rank-one matrices:

A=∑i=1rσiuiviT.A = \sum_{i=1}^{r} \sigma_i u_i v_i^T.A=∑i=1r​σi​ui​viT​.

Each term describes one component of the matrix. The largest singular values correspond to the components that contribute most strongly to the matrix’s size and structure.

For many applications, retaining every component is unnecessary. A matrix may contain a large amount of detail, while only a smaller number of components capture its most important patterns. Keeping the first kkk SVD terms gives the rank-kkk approximation

Ak=∑i=1kσiuiviT.A_k = \sum_{i=1}^{k} \sigma_i u_i v_i^T.Ak​=∑i=1k​σi​ui​viT​.

This is useful when a matrix has high rank but its essential structure can be represented with substantially fewer components.


Matrix norms and measuring approximation error

An approximation is only “best” relative to a way of measuring error. A norm assigns a nonnegative size to a vector or matrix and satisfies key properties:

  • Positivity: a norm is nonnegative and is zero only for the zero object.

  • Homogeneity: scaling an object by a scalar scales its norm by the scalar’s absolute value: ∥cv∥=∣c∣∥v∥\|cv\| = |c|\|v\|∥cv∥=∣c∣∥v∥.

  • Triangle inequality: ∥v+w∥≤∥v∥+∥w∥\|v+w\| \leq \|v\|+\|w\|∥v+w∥≤∥v∥+∥w∥.

Matrix norms have corresponding properties. Different norms emphasize different aspects of a matrix, so the choice of norm can matter in an optimization problem.

Vector norms

For a vector v=(v1,…,vn)Tv = (v_1,\ldots,v_n)^Tv=(v1​,…,vn​)T, common norms include:

  • Euclidean or L2L_2L2​ norm: the ordinary length of the vector,

    ∥v∥2=∑i=1nvi2.\|v\|_2 = \sqrt{\sum_{i=1}^{n} v_i^2}.∥v∥2​=∑i=1n​vi2​​.
  • L1L_1L1​ norm: the sum of the absolute values of the components,

    ∥v∥1=∑i=1n∣vi∣.\|v\|_1 = \sum_{i=1}^{n} |v_i|.∥v∥1​=∑i=1n​∣vi​∣.
  • Infinity norm: the largest absolute component,

    ∥v∥∞=max⁡i∣vi∣.\|v\|_\infty = \max_i |v_i|.∥v∥∞​=maxi​∣vi​∣.

The Euclidean norm measures ordinary geometric length. The L1L_1L1​ norm is especially important in optimization: in many appropriately formulated problems, minimizing an L1L_1L1​-based objective encourages sparse solutions, meaning solutions with many zero components. Sparse solutions can be easier to interpret than solutions containing many small, nonzero values. This property is used in areas such as signal processing and sensing.

Matrix norms determined by singular values

Three important matrix norms can be calculated from the singular values of AAA.

  • Spectral or matrix L2L_2L2​ norm: the largest singular value,

    ∥A∥2=σ1.\|A\|_2 = \sigma_1.∥A∥2​=σ1​.

    It measures the greatest amount by which AAA can stretch a unit vector.

  • Frobenius norm: the square root of the sum of the squares of all matrix entries,

    ∥A∥F=∑i,jaij2=∑i=1rσi2.\|A\|_F = \sqrt{\sum_{i,j} a_{ij}^2} = \sqrt{\sum_{i=1}^{r} \sigma_i^2}.∥A∥F​=∑i,j​aij2​​=∑i=1r​σi2​​.

    This treats a matrix as though its entries formed one long vector.

  • Nuclear norm: the sum of the singular values,

    ∥A∥∗=∑i=1rσi.\|A\|_* = \sum_{i=1}^{r} \sigma_i.∥A∥∗​=∑i=1r​σi​.

    The nuclear norm is sometimes viewed as a matrix analogue of the vector L1L_1L1​ norm.

These norms are useful in low-rank approximation because they depend only on the singular values. They are unchanged by orthogonal transformations applied on the left or right:

∥Q1AQ2∥=∥A∥,\|Q_1 A Q_2\| = \|A\|,∥Q1​AQ2​∥=∥A∥,

for orthogonal matrices Q1Q_1Q1​ and Q2Q_2Q2​, when ∥⋅∥\|\cdot\|∥⋅∥ is any of the three norms above. Orthogonal transformations rotate or reflect data without changing its essential lengths or singular values.


The Eckart–Young theorem: the best rank-kkk approximation

The Eckart–Young theorem states that retaining the first kkk terms of the SVD gives a closest rank-kkk approximation to AAA under each of the spectral, Frobenius, and nuclear norms.

If BBB is any matrix of rank at most kkk, then

∥A−B∥≥∥A−Ak∥,\|A-B\| \geq \|A-A_k\|,∥A−B∥≥∥A−Ak​∥,

where ∥⋅∥\|\cdot\|∥⋅∥ is any of those three norms. Thus, AkA_kAk​ is not merely a convenient low-rank approximation: it is an optimal one for these error measures.

The amount of error left after truncation can also be expressed directly in terms of the discarded singular values:

  • Spectral norm error:

    ∥A−Ak∥2=σk+1.\|A-A_k\|_2 = \sigma_{k+1}.∥A−Ak​∥2​=σk+1​.
  • Frobenius norm error:

    ∥A−Ak∥F=∑i=k+1rσi2.\|A-A_k\|_F = \sqrt{\sum_{i=k+1}^{r} \sigma_i^2}.∥A−Ak​∥F​=∑i=k+1r​σi2​​.
  • Nuclear norm error:

    ∥A−Ak∥∗=∑i=k+1rσi.\|A-A_k\|_* = \sum_{i=k+1}^{r} \sigma_i.∥A−Ak​∥∗​=∑i=k+1r​σi​.

The result makes the SVD valuable for compression and approximation: it identifies which components to retain when only kkk rank-one pieces are available.

Example: a diagonal matrix

Consider

A=[4000030000200001].A = \begin{bmatrix} 4&0&0&0\\ 0&3&0&0\\ 0&0&2&0\\ 0&0&0&1 \end{bmatrix}.A=​4000​0300​0020​0001​​.

Its singular values are 4,3,2,14, 3, 2, 14,3,2,1. Its best rank-222 approximation is obtained by keeping the two largest singular values:

A2=[4000030000000000].A_2 = \begin{bmatrix} 4&0&0&0\\ 0&3&0&0\\ 0&0&0&0\\ 0&0&0&0 \end{bmatrix}.A2​=​4000​0300​0000​0000​​.

It may seem that another rank-222 matrix could do better by spreading its entries across the diagonal. But rank is a global constraint: changing the diagonal values while keeping rank low can require adding off-diagonal entries. Those extra discrepancies may increase the total error. The theorem guarantees that, under the three specified norms, no other rank-222 matrix has smaller error than A2A_2A2​.

Why orthogonal changes of coordinates preserve the result

If A=UΣVTA = U\Sigma V^TA=UΣVT and QQQ is orthogonal, then

QA=(QU)ΣVT.QA = (QU)\Sigma V^T.QA=(QU)ΣVT.

Since QUQUQU is also orthogonal, the singular values remain the diagonal entries of Σ\SigmaΣ. Multiplication by an orthogonal matrix changes the coordinate system but does not change the singular values or the three norms above. This invariance explains why an example involving a diagonal matrix represents a broader class of matrices with the same singular values.


Low-rank approximation and missing data

Low-rank methods are useful when a large matrix is incomplete or noisy. A common assumption is that the observed entries reflect a lower-dimensional structure, so the complete matrix can be approximated or inferred using a low-rank model.

Recommendations and preferences

A recommendation problem can be represented by a matrix whose rows correspond to people and whose columns correspond to movies or products. An entry records a person’s rating or preference. Because people do not rate every item, many entries are missing.

A recommender system uses the observed ratings to estimate missing ones. Low-rank structure can help because a relatively small number of underlying preference patterns may explain much of the variation across people and items. In some matrix-completion approaches, the nuclear norm is used as a tractable way to encourage low-rank solutions.

Imaging and incomplete measurements

Magnetic resonance imaging (MRI) and other imaging systems can also involve noisy or incomplete measurements. If only some measurements are collected, the corresponding image data are incomplete. Matrix-completion methods use the available information and assumptions about structure to estimate missing values. Nuclear-norm minimization is one approach used to promote a low-rank completion.

The appropriate norm depends on the problem. The Frobenius norm measures total squared error, the spectral norm focuses on the largest remaining singular component, and the nuclear norm sums the singular-value contributions. They are related but are not interchangeable in every optimization task.


Principal component analysis

Principal component analysis (PCA) is a linear method for finding the dominant directions of variation in a data set. It can be understood through the SVD and low-rank approximation.

Suppose each sample is described by two measurements, such as height and age. With nnn samples, arrange the data in a matrix with one sample per column:

A=[∣∣∣x1x2⋯xn∣∣∣].A = \begin{bmatrix} |&|&&|\\ x_1&x_2&\cdots&x_n\\ |&|&&| \end{bmatrix}.A=​∣x1​∣​∣x2​∣​⋯​∣xn​∣​​.

Here, each column xjx_jxj​ contains the measurements for sample jjj. The rows correspond to the measured features.

Centering the data

Before finding directions of variation, PCA typically centers each feature by subtracting its sample mean. For a feature with observations a1,…,ana_1,\ldots,a_na1​,…,an​, the mean is

aˉ=1n∑j=1naj.\bar{a} = \frac{1}{n}\sum_{j=1}^{n}a_j.aˉ=n1​∑j=1n​aj​.

Subtracting the mean from every observation in that feature makes its centered values sum to zero. When all features are centered, the data cloud is positioned around the origin. A point below the mean may then have a negative centered value, even if the original measurement—such as age—was positive.

Centering is important because PCA seeks directions of variation around the data’s average location. The principal line or plane is normally understood to pass through the mean of the original data.

Covariance describes variation and relationships

After centering, the sample covariance matrix is

C=1n−1AAT.C = \frac{1}{n-1}AA^T.C=n−11​AAT.

For ppp features, CCC is a p×pp \times pp×p matrix. Its diagonal entries are the sample variances of individual features; its off-diagonal entries describe how pairs of features vary together. For example, a positive covariance between height and age means that above-average values of one tend to occur with above-average values of the other.

The factor n−1n-1n−1 is the conventional denominator for a sample covariance matrix. The use of n−1n-1n−1 rather than nnn accounts for estimating the mean from the same observations. This scaling does not change the covariance matrix’s eigenvectors, so it does not change the principal directions.

The term sample or empirical covariance distinguishes a covariance calculated from observed data from one derived from a theoretical probability distribution.


PCA as a best-fitting line problem

For centered two-feature data, a PCA line is constrained to pass through the origin. Its direction is a unit vector

u=[u1u2].u = \begin{bmatrix} u_1\\ u_2 \end{bmatrix}.u=[u1​u2​​].

Each data point is projected onto this direction. The PCA line is chosen so that the sum of squared perpendicular distances from the points to the line is as small as possible. In higher dimensions, PCA finds a lower-dimensional subspace that minimizes the corresponding squared distances.

This is not the same as ordinary least squares. In standard least-squares regression, one variable is typically treated as the predictor and the other as the response. The errors are measured in the response direction—for example, as vertical distances from points to a line. PCA instead treats all measured features symmetrically and measures perpendicular distances to the fitted subspace.

The different error definitions generally produce different fitted lines. Ordinary least squares is appropriate when one variable is being predicted from another and errors in the response are the focus. PCA is appropriate when the goal is to summarize variation across the features without privileging one as the response.


Finding principal directions from the SVD

Let the centered data matrix have SVD

A=UΣVT.A = U\Sigma V^T.A=UΣVT.

Then

AAT=UΣ2UT.AA^T = U\Sigma^2 U^T.AAT=UΣ2UT.

Consequently, the columns of UUU are eigenvectors of AATAA^TAAT and therefore of the covariance matrix CCC. The singular values determine the associated eigenvalues:

λi=σi2n−1.\lambda_i = \frac{\sigma_i^2}{n-1}.λi​=n−1σi2​​.

The first left singular vector, u1u_1u1​, is the first principal direction. It is the direction along which the centered data have the greatest variance. The next left singular vector, u2u_2u2​, is perpendicular to the first and captures the greatest remaining variance, and subsequent principal directions continue in the same way.

The first singular value, σ1\sigma_1σ1​, measures the scale of the data’s variation along the first principal direction. It is not, by itself, the slope of a line relating two features. For two centered features, if

u1=[uheightuage],u_1 = \begin{bmatrix} u_{\text{height}}\\ u_{\text{age}} \end{bmatrix},u1​=[uheight​uage​​],

then, when uheight≠0u_{\text{height}} \neq 0uheight​=0, the principal line has slope

uageuheight.\frac{u_{\text{age}}}{u_{\text{height}}}.uheight​uage​​.

For uncentered measurements, the line passes through the mean point. Thus, the direction vector determines the line’s orientation, while the singular value indicates the amount of variation along it.


PCA as dimensionality reduction

Keeping only the first kkk principal components replaces the centered data matrix AAA with its rank-kkk SVD approximation AkA_kAk​. This compresses the data into a lower-dimensional representation while preserving as much of its dominant structure as possible under the relevant approximation criterion.

PCA is a linear method: it identifies directions and subspaces formed through linear combinations of the original features. It can summarize and simplify data effectively, but it cannot represent every nonlinear pattern. More complex methods may be needed when important relationships in the data are nonlinear.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent