Eigenvalues & Eigenvectors
Geometric intuition, spectral theorem, power iteration
You have customer behavioral data with 50 features. Three of them — features 3, 7, and 22 — are all variations of "how much did the user spend." They carry similar information while consuming three times the parameter weight in regularization and three times the compute in every matrix operation. If you could find the single direction that captures the spending signal, you would reduce noise, compute, and overfitting simultaneously. That direction is a principal component — an eigenvector.
A square matrix A has eigenvalue λ and eigenvector v if Av = λv. The matrix A acts on v by pure scaling — the direction does not change, only the magnitude. For a symmetric positive semidefinite matrix like a covariance matrix, all eigenvalues are ≥ 0 and all eigenvectors are orthogonal. This is what makes PCA geometrically clean: the principal components are mutually perpendicular directions.
The covariance matrix C = X^T X / (n-1). Its eigenvectors are the principal directions of variance in the data. Its eigenvalues tell you how much variance lies along each direction. The first eigenvector, with the largest eigenvalue, is the direction of maximum variance — this is PC1. The second eigenvector, orthogonal to PC1, is PC2. The eigenvalue ratio λ₁ / Σλᵢ tells you the fraction of total variance captured by PC1.
Spectral theorem: any real symmetric matrix A decomposes as A = Q Λ Q^T where Q is orthogonal (columns are eigenvectors) and Λ is diagonal (eigenvalues on diagonal). This decomposition separates the rotating part (Q) from the scaling part (Λ). For PCA, Q gives you the rotation into principal component space, and Λ tells you how much each direction matters. This "orthogonal matrix's columns are eigenvectors" fact is special to symmetric A, though — it is not a general property of orthogonal matrices. A generic orthogonal matrix (a rotation, say) is not diagonalized by its own columns, and can have no real eigenvectors at all: the rotation R = [[0,−1],[1,0]] (a 90° turn) solves det(R−λI) = λ²+1 = 0, giving λ = ±i — no real eigenvalue, because no real vector keeps its direction under a genuine rotation; every real vector just gets turned 90°. The general 2D rotation R(θ) = [[cos θ,−sin θ],[sin θ,cos θ]] has eigenvalues λ = cos θ ± i·sin θ = e^{±iθ}, real only at θ=0 (λ=1, R=I) or θ=180° (λ=−1, R=−I). Symmetric matrices are guaranteed real eigenvalues and orthogonal eigenvectors; non-symmetric matrices are not.
Multiplying Q Λ Q^T out column by column turns the matrix form into a sum of rank-1 matrices: A = Σᵢ λᵢ vᵢ vᵢ^T, where each vᵢvᵢ^T is a rank-1 projector — project onto the line spanned by vᵢ, then scale by λᵢ. Worked example: A = [[4,1],[1,4]] has eigenvalues λ₁=5 with eigenvector v₁=[1,1]/√2, and λ₂=3 with eigenvector v₂=[1,−1]/√2. Check the sum directly: 5·v₁v₁^T = 5·[[0.5,0.5],[0.5,0.5]] = [[2.5,2.5],[2.5,2.5]], and 3·v₂v₂^T = 3·[[0.5,−0.5],[−0.5,0.5]] = [[1.5,−1.5],[−1.5,1.5]]; adding them gives [[4,1],[1,4]] = A. So A is nothing more than "project onto v₁ and stretch by 5" plus "project onto v₂ and stretch by 3" — the sum-of-rank-1-projectors view and the QΛQ^T matrix view are the same object, just written two different ways.
NOT this. Eigenvalues are not a mathematical abstraction with limited practical use. The eigenvalues of a neural network's Hessian determine optimization dynamics: a flat loss landscape has many near-zero eigenvalues sitting alongside a few large ones, so the condition number κ = λ_max/λ_min is huge. Vanilla SGD uses one global step size, capped by the steepest direction (λ_max) so it doesn't diverge there — which forces that same tiny step size onto the near-zero-eigenvalue flat directions too, so progress along those directions crawls. Adam instead rescales each parameter's step by a running estimate of that parameter's own gradient magnitude, which approximates dividing by the local curvature per direction — so in the same update it can take a large step along a flat (near-zero-eigenvalue) direction and a small step along a steep (large-eigenvalue) direction. That per-direction rescaling — not the mere presence of near-zero eigenvalues — is why Adam with good initialization typically converges faster than vanilla SGD on the same ill-conditioned, overparameterized loss surface. The eigenvalues of the attention matrix determine how information diffuses through a transformer layer. The eigenvalue spectrum of X^T X tells you the effective dimensionality of your data before you fit any model. Eigenvalues are the fingerprint of every matrix that matters in ML.
Key points
- When features are correlated, eigendecompose the covariance matrix before modeling. The eigenvalue spectrum tells you how many truly independent directions of variation exist in your data. If 5 of 50 eigenvalues contain 90% of the variance, you can reduce to 5 components with negligible information loss — the remaining 45 components are dominated by noise and correlations, not signal.
- Trap: forgetting to center data before computing the covariance matrix. If the mean is nonzero, the first eigenvector points toward the mean rather than toward the direction of maximum variance. Always subtract the column means from X before computing X^T X / (n-1). sklearn's PCA does this by default. If you compute the covariance matrix manually, centering is mandatory.
- Diagnostic: plot the explained variance ratio (eigenvalue_i / sum of all eigenvalues) as a cumulative curve. The elbow in the curve tells you how many components to keep. Where the curve flattens, adding more components yields diminishing returns — each additional component explains only noise. A sharp elbow at k components means the data lies approximately on a k-dimensional subspace.
- Power iteration finds the dominant eigenvector without ever forming the full eigendecomposition: starting from any v₀, repeatedly apply v ← Av/‖Av‖. Expand v₀ in the eigenbasis, v₀ = Σᵢ cᵢvᵢ; then Aᵏv₀ = Σᵢ cᵢλᵢᵏvᵢ = λ₁ᵏ(c₁v₁ + Σᵢ>1 cᵢ(λᵢ/λ₁)ᵏvᵢ). Since |λᵢ/λ₁| < 1 for every i>1, those terms shrink geometrically with k and only the c₁v₁ term survives — the ‖Av‖ normalisation at each step just prevents overflow/underflow, it doesn't change which direction wins. The convergence rate is |λ₂/λ₁|ᵏ: a large spectral gap (λ₁ ≫ λ₂) converges in a handful of iterations, a near-tie (λ₁≈λ₂) converges slowly. This is the algorithm behind PageRank: the dominant eigenvector of the web's link-transition matrix is the PageRank vector, found by repeated multiplication rather than by eigendecomposing a matrix with billions of rows.
The eigenvalue spectrum of your covariance matrix is a complete picture of your data's intrinsic dimensionality. Check it before choosing a model — it tells you whether you have 50 independent features or 5 directions of variation dressed up as 50.
Recap
- Av = λv: the matrix scales v without rotating it. Eigenvectors are the invariant directions.
- Covariance C = XᵀX/(n−1): its eigenvectors are principal directions, eigenvalues the variance along each.
- PC1 = eigenvector with largest eigenvalue = direction of max variance; λ₁/Σλᵢ = fraction of variance captured.
- Symmetric PSD (covariance) ⟹ eigenvalues ≥ 0, eigenvectors orthogonal — this is what makes PCA clean.
- Spectral theorem: A = QΛQᵀ separates rotation (Q) from scaling (Λ).
- Center data first — otherwise the first eigenvector points at the mean, not the max-variance direction.
- Scree/explained-variance elbow tells you how many components to keep; the flat tail is noise, not signal.
Check your understanding
Q1. What are the eigenvalues and eigenvectors of a rotation matrix R(θ) = [[cos θ, −sin θ], [sin θ, cos θ]]?
- A) The eigenvalues are cos θ ± sin θ (real values). The eigenvectors are [cos θ, sin θ]ᵀ and [−sin θ, cos θ]ᵀ — the columns of the rotation matrix itself. This holds because the columns of any orthogonal matrix are its eigenvectors, and rotation matrices are orthogonal, giving R = QΛQᵀ with Λ = diag(cosθ+sinθ, cosθ−sinθ).
- B) The eigenvalues are always λ₁=1, λ₂=1 because rotation preserves lengths: ‖Rv‖=‖v‖ for all v, so the scaling factor is always 1. The eigenvectors are the axes of rotation. For 2D rotations with θ≠0, the only axis is the origin, so applying the characteristic equation gives (1−λ)²=0, a double root regardless of θ.
- C) det(R − λI) = (cosθ − λ)² + sin²θ = 0 → λ² − 2λcosθ + 1 = 0 → λ = cosθ ± i·sinθ = e^{±iθ}. For θ ≠ 0, π, the eigenvalues are complex — there are no real eigenvalues, since no real vector keeps its direction under a genuine rotation. At θ=0, R=I (both eigenvalues 1); at θ=π, R=−I (both eigenvalues −1).
- D) The eigenvalues are real only when θ = kπ for integer k (0°, 180°, etc.). For general θ, R has no eigenvalues because eigenvalue equations require real solutions. The characteristic polynomial's real part gives a single real eigenvalue λ=cosθ with multiplicity 2, and the imaginary part sinθ is discarded as a numerical artifact.
Q2. A symmetric matrix A has eigenvalues λ₁=5, λ₂=3, λ₃=1 and orthonormal eigenvectors v₁, v₂, v₃. Write A as a sum of rank-1 matrices, and explain what this means geometrically.
- A) By the spectral theorem (A symmetric ⟹ A = QΛQᵀ, Q=[v₁,v₂,v₃], Λ=diag(5,3,1)): A = Σᵢ λᵢvᵢvᵢᵀ = 5v₁v₁ᵀ + 3v₂v₂ᵀ + 1v₃v₃ᵀ. Each vᵢvᵢᵀ is a rank-1 projector onto vᵢ. Geometrically: A stretches space by 5× along v₁, 3× along v₂, 1× along v₃ — a unit sphere maps to an ellipsoid with semiaxes 5, 3, 1 along the eigenvectors.
- B) A = v₁v₁ᵀ + v₂v₂ᵀ + v₃v₃ᵀ since the eigenvectors are orthonormal and span ℝ³. The eigenvalues λ₁=5, λ₂=3, λ₃=1 scale the matrix as a whole rather than the individual rank-1 components. Geometrically: each rank-1 term projects onto one axis of the eigenbasis; A is the sum of all three projections, equal to the identity matrix in the eigenbasis.
- C) A = 5·(v₁+v₂+v₃)(v₁+v₂+v₃)ᵀ/‖v₁+v₂+v₃‖² using only the dominant eigenvalue. The other eigenvalues contribute smaller corrections: A ≈ 5v₁v₁ᵀ with error ‖A−5v₁v₁ᵀ‖_F = √(9+1) = √10. Geometrically: A is approximately a rank-1 matrix pointing along v₁, with small perturbations along v₂ and v₃.
- D) A = (5+3+1)·v_avg v_avgᵀ where v_avg = (v₁+v₂+v₃)/‖v₁+v₂+v₃‖. The spectral theorem decomposes A into a single rank-1 matrix scaled by the sum of eigenvalues. Geometrically: A uniformly stretches all vectors by 9× in the average eigenvector direction, matching tr(A)=9 since trace equals the eigenvalue sum.
Q3. The power iteration algorithm computes the dominant eigenvector of A by repeatedly multiplying v ← Av/‖Av‖. Which TWO of the following statements correctly explain why this converges to the eigenvector for the largest eigenvalue?
- A) Power iteration works because matrix multiplication is associative: Aᵏv = A(A(...(Av)...)). At each step, the component of v along the dominant eigenvector grows relative to the others (by a factor of λ₁/λᵢ each iteration), so after k steps that direction dominates. This requires a unique dominant eigenvalue (|λ₁|>|λ₂|) and c₁≠0, i.e. v₀ not orthogonal to v₁.
- B) Expand v₀ in the eigenbasis: v₀ = Σᵢ cᵢvᵢ. Applying A k times: Aᵏv₀ = Σᵢ cᵢλᵢᵏvᵢ = λ₁ᵏ(c₁v₁ + Σᵢ>1 cᵢ(λᵢ/λ₁)ᵏvᵢ). Since |λᵢ/λ₁|<1 for i>1, those terms vanish as k→∞, leaving just c₁v₁. Convergence rate is |λ₂/λ₁|ᵏ, fast when the spectral gap is large; PageRank uses exactly this on the web graph's transition matrix.
- C) Power iteration converges because the gradient of ‖Av‖₂ with respect to v points toward the dominant eigenvector. Each normalised multiplication step performs a projected gradient ascent on the Rayleigh quotient vᵀAv/vᵀv, which is maximised at the dominant eigenvector. The convergence rate equals the learning rate times the spectral gap, roughly α·(λ₁−λ₂).
- D) Power iteration converges because symmetric matrices have orthogonal eigenvectors. Starting from any v₀, each multiplication by A rotates v toward the dominant eigenvector direction. After k rotations, the angle between v and v₁ decreases geometrically at rate cos(θ/k). Non-symmetric matrices may not converge because their eigenvectors are not orthogonal.
Try it interactively
ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.
Open ML Systems Lab →