Step 4 of 6
Eigenvectors, PCA & SVD
Eigenvectors are the directions a transformation doesn't turn. From there: PCA for dimensionality reduction, SVD for matrix compression, and why both are everywhere in ML.
18 min read
Most vectors change direction when you transform them. Eigenvectors don't - they only get scaled. Finding these special directions unlocks the most powerful tools in applied mathematics: PCA, spectral analysis, and matrix decompositions that compress information with minimal loss.
Eigenvectors - the directions that survive#
Apply a matrix A to most vectors and they change both direction and magnitude. An eigenvector v is one that only gets scaled - it stays on its own line:
v is an eigenvector of A with eigenvalue λ: applying A just stretches v by factor λ.
The scalar λ is the eigenvalue - it tells you how much the eigenvector gets stretched. Negative λ flips the direction. λ = 0 means the eigenvector gets squashed to zero (it's in the null space).
Eigen example
[[1.5, 0.5], [0, 1]] · det 1.50
Symmetric (orthogonal eigenvectors)
[[2, 1], [1, 2]] · det 3
In the first example, [[1.5, 0.5], [0, 1]]: vectors along the x-axis stay put and get stretched by 1.5 (λ₁ = 1.5), while vectors along (−1, 1) stay on their line with λ₂ = 1. Every other direction gets turned.
Finding eigenvalues#
To find eigenvalues, we need Av = λv, which rearranges to (A − λI)v = 0. This has a non-trivial solution only when det(A − λI) = 0 - the characteristic equation.
The characteristic polynomial: set the determinant to zero and solve for λ.
For a 2 × 2 matrix, this gives a quadratic; for n × n, a degree-n polynomial. The solutions are the eigenvalues. Some are real, some complex (rotation matrices, for instance, have complex eigenvalues because no real direction stays fixed under rotation).
PCA - eigenvectors of the covariance matrix#
Principal Component Analysis finds the directions of greatest variance in your data. Compute the covariance matrix Σ, find its eigenvectors, and sort by eigenvalue (largest first). The top eigenvectors - the principal components - form the best low-dimensional basis for your data.
- 01Center the data (subtract the mean)
- 02Compute the covariance matrix Σ = XᵀX / (n−1)
- 03Find eigenvectors and eigenvalues of Σ
- 04Keep the top k eigenvectors as principal components
- 05Project data onto the k-dimensional subspace
The eigenvalues tell you how much variance each component captures. If the first two eigenvalues account for 95% of total variance, a 2D projection loses almost nothing - the other dimensions were mostly noise.
In ML: PCA is used for feature reduction, visualization (project to 2D), denoising, and understanding what your data's true dimensionality is. It's also the mathematical foundation for whitening, decorrelation, and several normalization schemes.
- PCA
- Principal Component Analysis - finds the directions of greatest variance in the data, letting you reduce dimensions while keeping the most important structure.
- Whitening
- Transforms data so each feature has unit variance and features are uncorrelated - often a preprocessing step that speeds up training.
- Decorrelation
- Removing linear relationships between features so they carry independent information - PCA does this by aligning axes with the principal components.
SVD - the universal decomposition#
The Singular Value Decomposition factors any matrix (even non-square) into three parts:
U: left singular vectors (rotation). Σ: singular values (scaling). Vᵀ: right singular vectors (rotation). Any matrix = rotate × scale × rotate.
The singular values σ₁ ≥ σ₂ ≥ ... ≥ 0 on the diagonal of Σ measure the importance of each component. Keeping only the largest k singular values gives the best rank-k approximation of A - optimal in the sense that no other rank-k matrix is closer (in Frobenius norm).
| What SVD reveals | ML application |
|---|---|
| The top singular vectors | Principal components (PCA via SVD is more stable than via eigendecomposition) |
| The singular values | How much information each component carries |
| Low-rank structure | LoRA, matrix compression, latent factor models |
| The rank of the matrix | How many independent dimensions the data actually uses |
Eigendecomposition vs. SVD#
Eigendecomposition (A = PDP⁻¹) works only on square matrices and isn't always possible (defective matrices). SVD works on any matrix and always exists. For symmetric matrices, the two are closely related: the singular values are the absolute values of the eigenvalues, and the singular vectors are the eigenvectors.
Spectral properties in training dynamics#
The eigenvalues of the Hessian (the matrix of second derivatives of the loss) describe the curvature of the loss landscape:
- Large eigenvalues → steep directions → the loss changes quickly; learning rate must be small
- Small eigenvalues → flat directions → the loss barely changes; optimization is slow
- Negative eigenvalues → saddle points → not a local minimum
The ratio of the largest to smallest eigenvalue is the condition number - it measures how elongated the loss landscape is. A large condition number means gradient descent zigzags; this is why optimizers like Adam, which adapt per-parameter learning rates, work better than vanilla SGD on ill-conditioned problems.
- Hessian
- The matrix of second partial derivatives of the loss function - its eigenvalues describe how curved the loss landscape is in each direction.
- Condition number
- Ratio of the largest to smallest eigenvalue - a high condition number means the problem is 'elongated' and gradient descent will zigzag instead of converging smoothly.
- Adam
- An optimizer that adapts the learning rate per parameter using running averages of gradient magnitude, handling ill-conditioned problems better than vanilla SGD.
- SGD
- Stochastic Gradient Descent - updates parameters using the gradient from a random mini-batch of data, the simplest and most fundamental optimizer.
Where it shows up in ML#
PCA = top eigenvectors
The principal components are the eigenvectors of the covariance matrix, sorted by eigenvalue - the directions of greatest variance.
SVD compresses matrices
Any matrix factors into rotation × scaling × rotation. Truncating gives the best low-rank approximation.
LoRA exploits low rank
Weight updates in fine-tuning have low effective rank - LoRA explicitly parameterizes this as BA with small inner dimension.
Hessian eigenvalues = curvature
The condition number of the Hessian determines how well gradient descent behaves - and why adaptive optimizers help.