Recommended resources
The freely available resources this lesson will direct you to.
Hello. In the previous lesson, you treated dimensions as a contract: a matrix expression must be both shape-valid and semantically meaningful. That same discipline now makes PCA much easier to reason about. With examples as rows, we will move from a centered data matrix to a lower-dimensional representation , where .
This lesson explains the linear-algebra story behind dimensionality reduction: eigenvectors identify useful directions, eigenvalues quantify variance along those directions, and singular value decomposition computes the same PCA structure directly from the data matrix. By the end, you should be able to give a concise, technically sound PCA explanation in an ML interview and describe the trade-offs that matter in a production or vision setting.
Eigenvectors: directions a transformation preserves
Before using eigenvectors for data, separate the general concept from PCA.
For a square matrix , a nonzero vector is an eigenvector if applying changes only its scale, not its direction:
The scalar is the associated eigenvalue. If , the vector is stretched threefold. If is between zero and one, it is compressed. A negative value also reverses direction.
The important geometric idea is not the calculation procedure. It is that eigenvectors reveal an intrinsic coordinate system for a transformation: directions along which the transformation behaves as simple scaling.
Eigenvectors and eigenvalues | Chapter 14, Essence of linear algebra
Watch “Eigenvectors and eigenvalues” from 3Blue1Brown for the geometric intuition behind directions that remain on their own span under a matrix transformation.
Watch the visual intuition. Focus on the distinction between most vectors, which are moved off their original line, and eigenvectors, which stay on that line and are only scaled. The PCA connection comes later: a covariance matrix has particularly useful eigenvectors because they define the major directions of variation in data.
For PCA, the matrix of interest is the feature covariance matrix. Under the row-per-example convention established last lesson, begin with centered data:
Here, has a mean of zero in every feature column. Its covariance matrix is:
Dimension-check it:
Because is symmetric, its eigenvectors can be chosen to be orthonormal. Because it is a covariance matrix, its eigenvalues are nonnegative.
In PCA, this equation has a concrete interpretation:
- is a direction in the original feature space.
- is the variance of the centered data when projected onto that direction.
- Eigenvectors with large eigenvalues identify directions along which the data varies most.
A principal component is therefore not usually one original feature. It is a linear combination of features. If a component has substantial weights on several visual embedding channels, it captures a correlated pattern across those channels rather than selecting a single channel.
One subtle but important interview point: the sign of an eigenvector is arbitrary. Both and define the same one-dimensional axis, merely with reversed coordinates. Do not interpret the sign of a PCA component in isolation without considering this ambiguity.
PCA: preserve variation by minimizing reconstruction error
Imagine a two-dimensional point cloud shaped like a long, narrow ellipse. Projecting the points onto the ellipse’s long axis preserves most of their structure; projecting onto its short axis collapses much more information.
PCA formalizes this idea. It finds orthogonal directions that retain as much variance as possible, or equivalently, that minimize squared reconstruction error after projecting the data into a -dimensional subspace.
StatQuest: Principal Component Analysis (PCA), Step-by-Step
Watch “StatQuest: Principal Component Analysis (PCA), Step-by-Step” by StatQuest with Josh Starmer for the connection between projection, maximum variance, and reconstruction error.
First watch finding PC1. Notice why centering is required and why maximizing the spread of projected points is equivalent to minimizing their squared distance from the chosen line. Then jump to explained variance for the interpretation of eigenvalues as variance and the role of a scree plot.
Let the top eigenvectors of be the columns of:
The columns of are orthonormal:
The lower-dimensional coordinates, often called scores, are:
The dimensions make the operation explicit:
Each row of gives one example’s coordinates in principal-component space. The first column is its score on PC1, the second is its score on PC2, and so on.
To approximately reconstruct the original centered features:
Finally, add the mean back:
The PCA optimization problem can be written as:
The solution is to choose the eigenvectors corresponding to the largest eigenvalues. Large eigenvalues represent directions that retain substantial variation. Discarded low-eigenvalue directions contribute comparatively little to the optimal linear reconstruction.
Read Sebastian Raschka’s concise PCA walkthrough to consolidate the algorithm: standardize when appropriate, compute an eigendecomposition or SVD, rank components, and select a reduced subspace.
In the section “PCA and Dimensionality Reduction,” read the motivation, then review the bullet-point summary immediately below it. In “1 - Eigendecomposition - Computing Eigenvectors and Eigenvalues,” focus on the covariance interpretation; it connects component directions to their variances. Finally, in “2 - Selecting Principal Components,” read the explained-variance discussion. Keep the distinction clear: eigenvectors provide directions, while eigenvalues rank those directions.
The PCA algorithm, with engineering-relevant choices
A standard PCA workflow has five steps.
-
Choose the feature representation.
This might be tabular features, image embeddings from a backbone, sensor features, or document embeddings. PCA operates on numerical vectors; it does not know what a feature means. -
Center each feature using its training-set mean.
PCA seeks directions of variation around the mean. Without centering, the first component can be dominated by the dataset offset rather than meaningful variation. -
Decide whether to standardize.
Standardization gives each feature approximately unit variance before PCA. It is appropriate when units or scales are arbitrary or incomparable, such as mixing speed, temperature, and counts. It is not automatically correct: if feature scale itself encodes meaningful importance, forcing all features to equal variance changes the problem. -
Compute the principal directions.
This is done through covariance eigendecomposition or, more commonly, SVD. -
Select components and transform the data.
Retain the top directions, project data into that coordinate system, then assess both information retention and downstream behavior.
For a perception example, suppose a vision model emits a -dimensional embedding per camera frame. PCA may compress these embeddings for storage, indexing, visualization, or a lightweight downstream model. But high retained variance does not prove that the compressed representation preserves rare pedestrians, difficult weather conditions, or safety-critical classes. Those properties need scenario-level evaluation after the transformation.
That distinction is particularly important in interviews:
PCA preserves high-variance structure, not necessarily label-relevant or safety-relevant structure.
Because PCA is unsupervised, it ignores class labels. A feature direction that is low variance globally can still be decisive for distinguishing a rare class. This is one reason PCA should be validated against the actual downstream metric rather than chosen solely by an explained-variance threshold.
Explained variance is a diagnostic, not a universal decision rule
Sort the covariance eigenvalues so that:
where is the rank of the centered data. The explained-variance ratio of component is:
The cumulative explained variance through component is:
A scree plot displays the explained variance of each component, often alongside cumulative variance. It helps identify diminishing returns: a few components may explain most of the variation, after which additional components contribute marginally.

This figure motivates a stronger selection method than “keep 95% variance”:
- Use explained variance to understand the geometry and form a reasonable range for .
- Evaluate several values of against the actual validation metric, latency, memory, and operational constraints.
- Choose the smallest that meets the relevant quality requirement with acceptable uncertainty.
For a retrieval embedding pipeline, relevant downstream checks might include recall at , latency, and index memory. For a perception classifier, they may include class-specific recall, calibration, and performance on rain, night, and occlusion slices. The right criterion follows the system objective, not PCA’s internal objective alone.
SVD: the practical route to PCA
The covariance approach is intuitive, but implementations commonly use singular value decomposition directly on the centered data matrix.
For a rank- centered matrix:
In the reduced or “thin” form, the shapes are:
The diagonal entries of , written , are singular values ordered from largest to smallest.
Substitute the SVD into the covariance definition:
Because the columns of are orthonormal, , so:
This identity is the bridge between SVD and PCA:
| PCA quantity | SVD equivalent |
|---|---|
| Principal directions | Columns of , the right singular vectors |
| PCA eigenvalues | |
| PCA scores | |
| Rank- reconstruction |
The terminology is worth keeping precise. Singular values are not the covariance eigenvalues; their squares, adjusted by the covariance normalization constant, are the covariance eigenvalues.
Using the top SVD factors gives:
This is the best rank- approximation to under squared reconstruction error. In practice, direct SVD is numerically well-supported and avoids explicitly constructing , which can be undesirable for very high-dimensional features and worsens numerical conditioning.
One further implication follows from centering: the number of nonzero components cannot exceed:
If there are far more features than examples, PCA cannot produce more than nonzero variance directions after centering.
An interview-ready explanation
A concise answer can be structured around problem, geometry, computation, and caveat:
“PCA is a linear dimensionality-reduction method. After centering the data, I compute orthogonal directions that maximize projected variance, which is equivalent to minimizing squared reconstruction error for a chosen number of components. These directions are the eigenvectors of the covariance matrix, and their eigenvalues give the variance captured along each direction. In practice, I usually compute PCA with truncated SVD: the right singular vectors are the principal directions, and squared singular values are proportional to covariance eigenvalues. I select the number of components using explained variance as a diagnostic, then validate downstream task quality and resource trade-offs. PCA is unsupervised, so retaining variance does not guarantee retention of rare-class or label-relevant signal.”
Three mistakes to avoid in that explanation:
-
“PCA selects the best original features.”
No. PCA usually creates new features that are mixtures of the originals. -
“The first component is the most important feature.”
It is the highest-variance direction, not automatically the most predictive or causally important direction. -
“A variance threshold proves the reduction is safe.”
It only measures reconstruction of the input representation. Downstream and slice-level evaluation remain necessary.
Key takeaways
Eigenvectors are directions that a matrix scales without rotating away from their span; eigenvalues quantify the scaling. For PCA, the covariance matrix’s eigenvectors become orthogonal principal directions, and its eigenvalues equal the data variance along those directions.
With centered row-wise data:
the top principal directions are stored in:
and the reduced representation is:
SVD provides the practical implementation:
The right singular vectors in are the PCA directions, while covariance eigenvalues are proportional to squared singular values. Finally, explained variance helps choose a candidate component count, but the correct final choice depends on downstream quality, safety slices, latency, and memory.
Next, you will move from the geometry of a model’s representation to its training mechanics: using the chain rule to compute gradients and explain gradient-based parameter updates.