The singular value decomposition
The factorization A = UΣVᵀ for every matrix: building it from AᵀA, what singular values measure, rank and the four subspaces, the best low-rank approximation and LoRA, PCA via the SVD, the pseudoinverse and least squares.
When eigenvectors are not enough
The topic Symmetric matrices and quadratic forms gave symmetric matrices a perfect description: an orthonormal basis of eigenvectors along which the matrix only stretches. Real data matrices are neither square nor symmetric. A dataset of examples with features is a matrix , and a linear layer maps to . For a rectangular matrix the equation does not even make sense: and live in different spaces.
Even a square matrix can let us down. Take the running example of this topic:
Its trace is and its determinant is , so its eigenvalues are . No real direction is merely stretched. Yet the geometry is simple: sends the unit circle to an ellipse, and an ellipse has two perpendicular axes.
The fix is to allow two orthonormal bases, one for the inputs and one for the outputs. Every matrix of rank factors as
Here and are orthogonal. Their columns and are the left and right singular vectors. The matrix has the same shape as and is zero except for its diagonal. The diagonal starts with the singular values and continues with zeros. This is the singular value decomposition, or SVD. Unlike an eigendecomposition, it exists for every real matrix of any shape.
The sum on the right reads as a recipe. Each term takes the component of the input along , scales it by and writes the result along . So is a sum of rank-one pieces, sorted from the most important to the least.
For a tall data matrix most columns of meet only the zero rows of . Libraries can skip them: np.linalg.svd(X, full_matrices=False) returns just the first columns.
Building the SVD from a symmetric matrix
Where do and the come from? From a symmetric matrix we already understand. The matrix is symmetric, and it is positive semidefinite, because
By the spectral theorem it has an orthonormal basis of eigenvectors with eigenvalues . Exactly of them are positive. Indeed, forces , so has the same null space as . By rank–nullity that null space has dimension , so exactly eigenvalues are zero. Now set
The are orthonormal for free: , which is for and otherwise. For we get , so . Complete to an orthonormal basis of . Then column by column, and multiplying by on the right gives .
Back to the running example. Here
with eigenvalues and and eigenvectors , . So and . Then and . A quick multiplication confirms .
Note what is: the length of the image of the unit vector . Singular values are square roots of eigenvalues of , not eigenvalues of itself, and they are never negative.
Rotate, stretch, rotate
Read from right to left. rotates (possibly with a reflection) so that each lands on the axis . stretches axis by and adds or drops dimensions. rotates to . Rotate, stretch, rotate.
So the unit circle goes to an ellipse with semi-axes and . In the running example the input direction becomes an axis of length , and the perpendicular becomes an axis of length . Both rotations turn by about .
The singular values answer the natural questions about the size of a matrix.
The spectral norm is the largest stretch of a unit vector, and it equals :
Indeed, is the Rayleigh quotient of , and its maximum is . For a square or tall the smallest stretch is likewise .
The Frobenius norm treats the matrix as one long vector of its entries:
The middle step holds because the -th diagonal entry of is . The last one holds because a trace is the sum of the eigenvalues, here . In the example, .
For a square the orthogonal factors have determinant , so . In the example, .
The ratio says how strongly the map flattens the circle. It is the condition number , and the topic Conditioning and numerical stability will show why it governs rounding errors.
Rank and the four subspaces
The rank of is the number of nonzero singular values. More than that, the SVD hands us orthonormal bases of all four subspaces from the topic Matrices and linear systems:
| Subspace | Dimension | Basis |
|---|---|---|
| column space of | ||
| null space of | ||
| row space of | ||
| null space of |
Why: is always a combination of , and reaches each . The same sum vanishes exactly when is orthogonal to , that is, when lies in the span of . The two subspaces of follow in the same way from .
Rank–nullity is visible at a glance: the right singular vectors split into for the row space and for the null space.
Take a wide matrix:
For a wide matrix it is cheaper to diagonalize , which has the same nonzero eigenvalues as . They are and , so , and the rank is . The third right singular vector is , and indeed : the null space is the line through .
In floating point an exact zero rarely survives. A singular value that should be zero comes out as or so. NumPy's matrix_rank therefore counts only the singular values above a tolerance:
The result is the numerical rank. The SVD is the reliable way to compute it, because is exactly the spectral-norm distance from to the nearest matrix of rank , as the next block shows. The pivots of elimination give no such guarantee. The upper triangular matrix with ones on the diagonal and everywhere above it has every pivot equal to , yet its : a change that small makes it singular.
An ML example: a feature table lists a price in rubles and the same price in dollars. One singular value of the data matrix is then zero up to rounding, far below the tolerance. Its right singular vector mixes the two price columns, and moving the weights along it does not change any prediction.
The best low-rank approximation
Cutting the sum after terms gives the truncated SVD
a matrix of rank . The Eckart–Young theorem says no matrix of rank at most does better, in either norm:
Both minima are reached at . The error values are easy to see: is itself an SVD with singular values . That nothing else beats is the deep part of the theorem.
In the running example . The error has spectral and Frobenius norm , which is of . With close to , this matrix is far from rank one.
Real data are usually kinder. In a grayscale image alone carries of , and rank reproduces the image with an relative error. And never has to be stored as an table: keeping the vectors , and the numbers is enough.
The same idea drives LoRA, a standard way to fine-tune large models. Instead of a full update of a weight matrix , it learns a rank- update
For a projection with this is parameters instead of , or . Eckart–Young prices the restriction: if the ideal update has singular values , any rank- update misses it by at least in Frobenius norm.
PCA is the SVD of centred data
The topic Symmetric matrices and quadratic forms found the direction of largest variance as the top eigenvector of the covariance matrix. The SVD gets there without forming the covariance at all.
Let be centred: every column has mean zero. Take its SVD, . The covariance matrix becomes
This is already a spectral decomposition of . So:
- the principal directions, or principal components, are the right singular vectors ;
- the variance of the data along is ;
- the coordinates of the examples in the new basis are the columns of ;
- the best reconstruction of from components is the truncation , by Eckart–Young.
The total variance is , the sum of the variances along all the directions .
Check it on the four centred points of that topic, , , and . Their matrix has and , so the variances are and : exactly the eigenvalues of found there. And is the same top eigenvector.
Why not simply diagonalize ? Because forming it squares the singular values. Rounding the entries of moves its eigenvalues by about . So a component with below about drowns in rounding errors, while the SVD of itself still resolves it. For singular values , and , the SVD returns ; the route through returns rounding noise of order . This is why PCA in scikit-learn computes the SVD of directly.
The pseudoinverse and least squares
The topic Inner products, norms and orthogonality solved least squares with the normal equations, assuming independent columns. Often they are not independent: a duplicated feature, or more weights than examples. Then infinitely many minimize . The SVD picks the shortest one. Define the pseudoinverse
where is transposed, with each nonzero replaced by and zeros left as zeros.
Why it works: change coordinates to and . Both changes are rotations, so lengths stay the same, and
The first sum vanishes at . The with do not affect the residual at all, so setting them to zero gives the shortest solution. For the wide matrix and every solution is , and is the shortest of them.
Two special cases connect to earlier topics. For a square invertible , . For independent columns, , the normal equations.
Small singular values are dangerous: amplifies the noise in . Libraries cut off tiny (the rcond argument in NumPy), and ridge regression softens into .
One more fact links this to training. Gradient descent started from zero on an underdetermined least-squares problem converges to exactly : it never leaves the row space. To see why, and to train models that are not linear at all, we need derivatives. The next topic, Derivatives and Taylor series, starts the calculus part of the course.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Go deeper — optional
Code and labs do not count toward the main percentage or the certificate.
- SVD rank-1 reconstructionoptional
Build σ1 u1 v1ᵀ; compare Frobenius error to the full matrix.
~20 min · easier on a computer · The matching course topic has been read.
Self-check in the notebook — not part of mastery or the certificate.
Answers are saved on the server and tied to this browser until you sign in.