Hello! Welcome back to our exploration of Principal Component Analysis.
In our last lesson, we built the conceptual foundation for PCA. We saw that its primary goal is to find a new, more informative basis for our data. This new basis is built from orthogonal directions of maximum variance, called principal components. Algebraically, this is equivalent to finding a transformation that diagonalizes the data's covariance matrix, thereby eliminating redundancy and ordering the new axes by importance.
Today, we will connect that conceptual framework to a powerful computational tool you're already familiar with: the Singular Value Decomposition (SVD). Our goal is to see precisely how the principal components of a dataset are related to the singular vectors of the centered data matrix. This will not only give us a robust algorithm for performing PCA but also provide a deeper understanding of what the SVD reveals about data.
1. From Covariance to SVD: Two Paths to the Same Goal
As we concluded last time, the principal components are the axes of a new coordinate system aligned with the data's spread. Mathematically, these axes are the eigenvectors of the data's covariance matrix.
Let's formalize this. Assume we have a data matrix with samples (rows) and features (columns).
- First, we mean-center the data by subtracting the mean of each column from all entries in that column. Let's call this centered matrix .
- The sample covariance matrix is then given by . This is a symmetric matrix.
- The principal components are the eigenvectors of this covariance matrix , ordered by the size of their corresponding eigenvalues. The eigenvalues themselves represent the variance of the data along each principal component direction.
This gives us one clear method: form the covariance matrix and find its eigenvectors. However, there is a more direct and numerically stable way using SVD. Let's see how these two paths converge.
2. The SVD Connection
The main insight for today's lesson is that we can bypass the explicit calculation of the covariance matrix. The SVD of the centered data matrix itself gives us the principal components.
The following video provides an excellent walkthrough of the entire PCA process, culminating in the connection to SVD.
Principal Component Analysis (PCA)
Let's watch this video on Principal Component Analysis by Steve Brunton. It will walk us through the necessary steps of mean-centering the data and then explicitly show the relationship between the SVD of the data matrix and the eigenvectors of its covariance matrix.
Please watch from 3:45 to 10:19. The first segment (3:45 - 5:35) reviews the crucial step of mean-centering the data matrix. The second part (5:35 - 8:07) discusses computing the covariance matrix and its eigenvectors. The final, most important segment (8:07 - 10:19) directly connects this process to the SVD of the mean-centered data matrix. Pay close attention to how the principal components and loadings are derived from U, Sigma, and V.
Let's break down the beautiful mathematical connection shown in the video.
Let the SVD of our mean-centered data matrix be:
Now, let's construct the covariance matrix using this decomposition.
Using the property , we get:
Since the left singular vectors in form an orthonormal set of columns, we know that (the identity matrix). This simplifies the expression dramatically:
This final equation is incredibly revealing. It is the eigendecomposition of the covariance matrix .
- The columns of are the eigenvectors of .
- The diagonal matrix contains the eigenvalues of .
Since the principal components are, by definition, the eigenvectors of the covariance matrix, we have found them:
The principal components of the data are the right singular vectors (the columns of ) of the mean-centered data matrix .

To solidify this, let's turn to a more detailed textual explanation of this relationship.
How Are Principal Component Analysis and Singular Value Decomposition Related?
The article 'How Are Principal Component Analysis and Singular Value Decomposition Related?' provides a very clear, step-by-step derivation of this connection.
Please read the section 'Relation Between SVD and PCA'. This section mirrors the derivation we just did, confirming how the singular values relate to the eigenvalues of the covariance matrix and how the right singular vectors correspond to the principal components.
Test your understanding!
Suppose the SVD of a centered data matrix gives you a diagonal matrix of singular values and a matrix of right singular vectors . If you instead calculated the covariance matrix , what would its eigenvectors and eigenvalues be? Which vector corresponds to the direction of most variance in the data?
Show answer
The eigenvectors of would be the columns of : .
The eigenvalues () are related to the squared singular values () by . So, the eigenvalues would be:
The direction of most variance corresponds to the largest eigenvalue. This is , which corresponds to the eigenvector . Therefore, (the first right singular vector) is the first principal component.
3. The PCA Algorithm via SVD
This direct relationship gives us a robust and numerically stable algorithm for performing PCA, which is the standard approach in modern software packages. Given your background in computer science, it's worth noting that computing the SVD of is generally preferred over forming and finding its eigenvectors. Forming the product can lead to a loss of precision, an issue that specialized SVD algorithms are designed to avoid.
Here is the complete algorithm:
- Organize Data: Start with your dataset as an matrix , where is the number of samples and is the number of features.
- Center the Data: For each feature column, calculate its mean and subtract it from the column to produce the centered matrix .
- Compute SVD: Calculate the SVD of the centered matrix: .
- Identify Components and Scores:
- The principal components (the directions of variance) are the columns of the matrix . The first column of is the first principal component, the second column is the second, and so on.
- The principal component scores (the coordinates of the data in the new basis) are given by the matrix product . A little algebra shows this is simply . Each column of gives the scores for the corresponding principal component.
The singular values in tell you the importance of each component. The variance explained by the -th component is . By looking at these values, you can decide how many components to keep for dimensionality reduction.
Conclusion
In this lesson, we've solidified the connection between the abstract goal of PCA and its practical implementation via SVD. This is a cornerstone concept in data analysis, where the geometric interpretation of finding directions of maximum variance maps perfectly onto the algebraic decomposition of a matrix.
Key Takeaways:
- Principal Component Analysis can be performed in two equivalent ways: by finding the eigenvectors of the covariance matrix, or by computing the SVD of the centered data matrix.
- The principal components are precisely the right singular vectors () of the mean-centered data matrix.
- The eigenvalues of the covariance matrix are directly proportional to the squares of the singular values (), quantifying the variance along each principal component.
- The projected data points onto the new principal component axes, known as scores, are given by the columns of the matrix .
- Using SVD is the standard, numerically preferred method for computing PCA.
Preview of the Next Module:
This lesson concludes our module on "Applications in Data Analysis". We've seen how SVD is a golden thread connecting least squares, matrix approximation, and now PCA.
Our next module, "Tensor Products for Composite Systems," will take us in a new direction, one that is absolutely essential for your goal of studying quantum mechanics. We will learn how to combine vector spaces to describe systems made of multiple parts—for example, how to describe the state of two particles (or two qubits) when we know the state of each one individually. This will introduce concepts like the Kronecker product and the crucial quantum idea of entanglement.