Principal Component Analysis


Principal Component Analysis

Anna
Today we’re connecting the singular value decomposition to principal component analysis, or PCA. The central idea is that a large data matrix can contain more information than we need, so we want to keep its most important patterns without simply copying every entry.

Michael
That echoes a key idea in machine learning: learning should identify important facts in the data, not just memorize the training examples. The SVD gives us a principled way to decide which parts of a matrix are most important.

Anna
Recall the SVD: a matrix A can be written as a sum of rank-one pieces, each of the form sigma_i u_i v_i transpose. The u vectors are orthonormal, and so are the v vectors. The singular values sigma_i tell us the size of those pieces, usually ordered from largest to smallest.

Michael
So if we keep only the first k pieces, we get A_k, a rank-at-most-k approximation to A. The lecture’s key theorem, called the Eckart–Young theorem, says A_k is the closest rank-k approximation to A, for three important matrix norms.

Anna
In other words, take any other matrix B of rank k or less. Its error from A, measured in any of those three norms, cannot be smaller than the error from A_k. That’s what makes the truncated SVD more than a convenient shortcut: it solves an approximation problem optimally.

Michael
Before we name those matrix norms, let’s review vector norms. The L2 norm is the familiar length: square the components, add them, and take the square root. The L1 norm adds the absolute values of the components, while the infinity norm is the largest absolute component.

Anna
They each capture size in a different way. One reason the L1 norm is useful is that minimizing an objective with an L1 penalty can produce a sparse answer: a vector with mostly zero components. That can be easier to interpret than an answer full of small, nonzero values.

Michael
That’s the contrast the lecture draws with least squares, which uses the L2 norm and can leave you with many small components. L1 minimization appears in areas such as signal processing and sensing, and is also known as basis pursuit in this context.

Anna
A norm has basic rules: it is nonnegative, scaling a vector by a constant scales its norm by the absolute value of that constant, and it obeys the triangle inequality. Matrix norms follow corresponding rules, but there are many possible ways to measure a matrix’s size.

Michael
The first matrix norm here is the L2, or spectral, norm: it is the largest singular value, sigma_1. The second is the Frobenius norm. Treat the matrix entries as one long vector, square them, add them all, and take the square root.

Anna
The third is the nuclear norm, which adds up the singular values. These three norms are especially useful here because each depends only on the singular values, and the truncated-SVD approximation has the Eckart–Young optimality property for all three.

Michael
That choice of norm can matter in applications. The lecture uses the Netflix recommendation problem as an example: subscribers had rated some movies but not others, leaving a large matrix with missing entries. The task was to estimate the missing ratings, and the nuclear norm was identified as a useful choice for that matrix-completion problem.

Anna
The same general idea comes up with MRI images. If a scan does not collect enough measurements to fill in the whole image matrix, some entries are missing. A matrix-completion approach can estimate them, and the lecture points to the nuclear norm as a useful tool there too.

Michael
Let’s make the rank-k theorem concrete. Suppose A is diagonal with diagonal entries 4, 3, 2, and 1. Its singular values are those same numbers, so its best rank-two approximation keeps the two largest pieces: the diagonal entries 4 and 3, with the rest set to zero.

Anna
It might seem that another rank-two matrix could do better by spreading the approximation around. For instance, you could try changing the leading entries to 3.5 and 3.5, and use the remaining rank-one piece to approximate the smaller entries. That can make some diagonal errors look smaller, but keeping the rank at two forces changes elsewhere, such as off-diagonal entries.

Michael
Those extra errors count too. The theorem says that, under the specified norms, this alternative cannot beat the approximation formed from the first two SVD pieces. So simply choosing the largest singular-value pieces is optimal, even when a competing rank-two construction looks tempting.

Anna
And the diagonal example is not restrictive. If A is U times a diagonal singular-value matrix times V transpose, multiplying by orthogonal matrices changes the directions of the pieces but not their singular values. The same singular-value information governs the approximation.

Michael
That invariance is connected to a familiar fact about vectors. An orthogonal matrix can rotate or reflect a vector without changing its L2 length. For matrices, multiplying by an orthogonal matrix preserves these singular-value-based norms; in the SVD it changes the orthogonal factors, not the diagonal matrix of singular values.

Anna
Now let’s turn to PCA. Imagine a dataset with two measurements for each person, such as height and age. Put the measurements into a matrix, with the two variables as rows and the people as columns. Before looking for a pattern, subtract the mean of each row from that row.

Michael
Centering makes each variable’s average zero. Values below the original average become negative and values above it become positive. That shift lets us study the shape and relationships in the data around its center, rather than having the original averages dominate the picture.

Anna
PCA then looks for a line that best captures the centered data. Here, “best” means minimizing the sum of the squared perpendicular distances from the data points to the line. It’s a linear method: it looks for a linear pattern, rather than modeling every possible nonlinear relationship.

Michael
That objective is different from ordinary least squares regression. In a regression picture, you choose a direction for predicting one variable from another and measure residuals in that direction. PCA instead measures each point’s perpendicular distance to the line, so the two methods are solving different problems and need not produce the same line.

Anna
For centered data, the sample covariance matrix summarizes the variation. With the data arranged as described, it is A A transpose divided by N minus 1, where N is the number of observations. The entries capture each variable’s variance and the covariance that describes how the variables vary together.

Michael
The word “sample” matters: this covariance is calculated from the observed data, so it’s also called empirical covariance. The lecture notes that N minus 1 is the usual sample normalization; for finding the directions of the principal components, that scalar normalization does not change the directions.

Anna
Here’s how the SVD enters. If A equals U Sigma V transpose, then A A transpose equals U Sigma squared U transpose. So the columns of U give the directions associated with the covariance matrix, and the squared singular values describe how much variation lies in those directions, apart from the covariance normalization.

Michael
The first principal component is the direction with the largest variation, associated with the largest singular value. Keeping the first few such directions gives a lower-dimensional summary of the data, much like keeping the leading pieces of the SVD gives the best low-rank approximation.

Anna
So the full connection is: center the data, examine its covariance or its SVD, and use the leading directions to identify the dominant linear patterns. The lecture introduces this as the mathematical heart of PCA, while distinguishing it from least-squares regression and leaving the complete derivation of the best direction for further work.

Michael
And that’s why the SVD is so powerful: it both reveals dominant structure and tells us how to approximate a matrix when we can’t or don’t want to keep everything. In PCA, that same structure becomes a way to understand the main patterns of variation in data.

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