Singular Value Decomposition
Suppose a streaming service stores a matrix of ratings. Millions of users are matched against thousands of movies. Most entries are missing, and the ones that exist are noisy. Yet the service must recommend new titles with confidence. The key structural assumption that makes this tractable is that human preference is low-rank. A handful of latent tastes explains most of the variation in ratings. Singular Value Decomposition (SVD) is the tool that finds this hidden low-dimensional structure inside any matrix. It ranks the structure, compresses it, and denoises it, all from one factorization. SVD is arguably the single most useful theorem in applied linear algebra. It underlies Principal Component Analysis, powers recommender systems, and compresses images. It also solves ill-conditioned least-squares problems. It gives the cleanest possible answer to "what is the best rank- approximation of this matrix?" Eigendecomposition only exists in convenient form for square, diagonalizable matrices. The SVD, by contrast, exists for every real or complex matrix. This holds whether the matrix is rectangular or square, singular or not. This universality is why it sits at the mathematical core of numerical linear algebra. By extension, it sits at the core of machine learning. This article develops the SVD from first principles. It connects the SVD precisely to PCA, showing they are two views of the same computation. It also proves the Eckart–Young theorem that makes low-rank approximation optimal. We give a complete algorithmic account. We show how the decomposition is computed conceptually. We show how it is used for compression and denoising. We also cover the exact complexity and numerical stability tradeoffs involved. A full worked numerical example is traced by hand. Every step is checkable. By the end, you should be able to state precisely what the SVD guarantees. You should be able to derive its connection to eigenvalues of . You should be able to prove optimality of truncated SVD for rank- approximation. You should also recognize the pitfalls that trip up practitioners: sign ambiguity, rank-deficiency, and computational cost. This sets up later ideas in Manifold Learning and Nonlinear Dimensionality Reduction. There, the linear subspace assumption of SVD is relaxed.
- Every real matrix factors as with orthogonal and diagonal, nonnegative, decreasing.
- The singular values in are square roots of eigenvalues of (equivalently ); the columns of and are the corresponding eigenvectors.
- PCA is SVD applied to a mean-centered data matrix: principal components are right singular vectors, scores are .
- The Eckart–Young theorem proves that truncating the SVD to the top singular values gives the provably best rank- approximation in both Frobenius and spectral norm.
- Computing a full SVD costs time; truncated/randomized SVD reduces this drastically for large sparse matrices.
- SVD underlies recommender systems, image/data compression, noise reduction, pseudo-inverses, and latent semantic analysis.
The SVD decomposes any matrix into rotate–stretch–rotate, and truncating the stretch factors gives the provably optimal low-rank approximation of the matrix.
The idea
The Singular Value Decomposition states that every matrix can be written as
where is orthogonal (), is orthogonal (), and is diagonal with nonnegative entries on its main diagonal, called singular values. The columns of are left singular vectors, and the columns of are right singular vectors. Geometrically, acts on a vector by first rotating it (via ), then stretching it along coordinate axes by the factors (via ), then rotating again (via ). This decomposition always exists — no assumption of square shape, invertibility, or diagonalizability is needed — which is precisely why SVD is more broadly applicable than eigendecomposition. Eigendecomposition requires to be square and diagonalizable, and need not be orthogonal. The SVD sidesteps all of this by working with two different orthonormal bases (one for the domain, one for the codomain) instead of one shared basis. The connection to eigenvalues is direct. Since are orthogonal,
which is an eigendecomposition of the symmetric positive semi-definite matrix : the columns of are its eigenvectors, and the diagonal entries of (i.e., ) are its eigenvalues. Symmetrically, gives as the eigenvectors of . This is exactly how SVD connects to Principal Component Analysis: if is a mean-centered data matrix (rows are samples), then is the sample covariance matrix, whose eigenvectors are the principal component directions — and those eigenvectors are precisely the right singular vectors of .
How it works
Step 1 — reduce to an eigenproblem. Conceptually (not how numerical libraries do it internally, but mathematically equivalent), form , an symmetric positive semi-definite matrix. Its eigenvalues and orthonormal eigenvectors give the right singular vectors directly, with .
Step 2 — recover the left singular vectors. For each nonzero singular value, set
These are automatically orthonormal because , which is when and otherwise (using ). If (or there are zero singular values), extend to a full orthonormal basis of via Gram–Schmidt on any complementary vectors; these extra columns multiply zero rows of and do not affect .
Step 3 — assemble. Stack the as columns of , the as columns of , and place on the diagonal of in decreasing order. Then holds by construction, since applying both sides to each gives on both sides, and the form a basis. In practice, numerical libraries never explicitly form (this squares the condition number and loses precision); instead they use bidiagonalization followed by an implicit QR or divide-and-conquer iteration directly on . The pseudocode below presents the conceptual algorithm (correct and pedagogically transparent) alongside the key downstream use — truncated SVD for low-rank approximation. ```text function SVD(A): # A is m x n
# Conceptual computation (production code uses bidiagonal QR / divide&conquer) C := transpose(A) @ A # n x n, symmetric PSD (eigenvalues λ, eigenvectors v) := EIGENDECOMPOSE(C) sort λ descending; permute v to match for i in 1..n: σ[i] := sqrt(max(λ[i], 0)) # numerical floor at 0 for i in 1..rank: # rank = number of nonzero σ[i] u[i] := (A @ v[i]) / σ[i] extend {u[i]} to an orthonormal basis of R^m via Gram-Schmidt (fills U) V := columns v[1..n] U := columns u[1..m] Σ := m x n diagonal matrix with entries σ[1..min(m,n)] return U, Σ, V function TRUNCATED_SVD(A, k): U, Σ, V := SVD(A) U_k := first k columns of U Σ_k := top-left k x k block of Σ V_k := first k columns of V return U_k, Σ_k, V_k # A_k = U_k Σ_k V_k^T is the best rank-k approx function LOW_RANK_RECONSTRUCT(U_k, Σ_k, V_k): return U_k @ Σ_k @ transpose(V_k) # explicit m x n matrix, rank <= k ``` The truncated form is the workhorse in applications: instead of storing explicitly, one stores the three thin factors (), (), (), which is far cheaper when .
Complexity & correctness
Time complexity. Computing a full SVD of a dense matrix (assume without loss of generality) via the standard approach — Householder bidiagonalization followed by an implicit-shift QR or divide-and-conquer algorithm on the bidiagonal form — costs
for the singular values and alone, and (dominated by the same term when ) if is also required in full. More generally this is stated as , matching when . This dominates because bidiagonalization is a sequence of Householder reflections, each costing , and the subsequent bidiagonal SVD iteration converges in sweeps each costing per superdiagonal entry, giving lower-order terms. Forming explicitly (the conceptual algorithm above) costs just for the product and then for its eigendecomposition — asymptotically comparable but numerically inferior, since squaring squares its condition number and can destroy precision in small singular values. Production libraries (LAPACK's `gesdd`/`gesvd`) avoid this by working with directly.
Space complexity. Storing the full factorization needs in the worst case (full and ), but truncated SVD needs only for rank , which is the practically relevant figure since in most applications.
Randomized/truncated speedups. When only the top singular vectors are needed and is large or sparse, randomized SVD algorithms (Halko–Martinsson–Tropp) compute an approximate truncated SVD in time by projecting onto a random -dimensional subspace, orthogonalizing, and solving a small dense SVD on the projected matrix. This is the practical choice for matrices with millions of rows/columns, such as recommender-system rating matrices.
Correctness — existence. The existence of the SVD follows from the eigendecomposition of : it is symmetric and positive semi-definite (since ), so the spectral theorem guarantees real nonnegative eigenvalues and an orthonormal eigenbasis. The construction in Step 2 above (defining ) is then verified to yield orthonormal vectors satisfying for every , which is exactly the statement , i.e. since is orthogonal ().
Correctness — optimality (Eckart–Young theorem). The deepest correctness claim is that truncating the SVD gives the provably best low-rank approximation. Formally, for any matrix with ,
where is the truncated SVD. Moreover the exact approximation error is known in closed form:
Proof sketch. Write in its SVD basis; since Frobenius norm is invariant under orthogonal transformations, directly, giving the error formula for the truncated SVD. For optimality, suppose has rank ; its null space has dimension , so it intersects the span of the top right singular vectors (a -dimensional space) in a nonzero vector (by a dimension-counting argument: two subspaces of dimensions and inside must intersect nontrivially). Normalize ; then , so
using that for and . Hence no rank- matrix beats the truncated SVD in spectral norm, and a parallel argument (or the Frobenius-norm case of Mirsky's theorem) extends this to Frobenius norm. This is the mathematical fact that makes SVD the gold standard for compression, denoising, and dimensionality reduction: it is not merely a good heuristic but a certified optimum under two of the most natural matrix norms.
Tradeoffs. SVD assumes linear (subspace) structure; when data lies on a curved manifold, a linear rank- approximation can badly misrepresent geometry — this is exactly the gap that Manifold Learning techniques address. SVD is also sensitive to scale: features measured in different units will have their singular values dominated by scale rather than information content, so standardization (as in PCA) matters. Numerically, near zero are ill-determined and their corresponding are unstable to perturbation; truncation before this regime, guided by the spectrum, is standard practice.
Worked example
Consider the small matrix
Step 1: form .
Step 2: eigenvalues of . The characteristic equation is , so , giving , . Both positive, confirming positive semi-definiteness.
Step 3: singular values.
Step 4: eigenvectors of (right singular vectors). For : solve . Normalized: . For : . Normalized: .
Step 5: left singular vectors via .
Check norm: . ✓.
Check norm: . ✓. Check orthogonality . ✓.
Step 6: assemble and verify.
A direct multiplication reconstructs exactly (verified entrywise: e.g., entry is , matching ).
Rank-1 truncation. Keeping only :
The Eckart–Young theorem guarantees this is the closest rank-1 matrix to in Frobenius norm, with error exactly , which one can verify directly: , and indeed . ✓ This confirms the closed-form error formula on a concrete numeric case, not just symbolically.
| quantity | value |
|---|---|
| rank-1 Frobenius error | |
| fraction of "energy" retained by |
Common pitfalls & traps
| Pitfall | Why it happens | Fix |
|---|---|---|
| Forgetting to mean-center before treating SVD as PCA | SVD of raw data captures variation around the origin, not around the mean | Subtract column means before applying SVD if PCA semantics are wanted |
| Sign ambiguity of singular vectors | and give the same term | Never compare signs across runs/libraries directly; compare subspaces or use a canonical sign convention |
| Assuming are unique when singular values repeat | Any orthonormal rotation within a repeated- eigenspace is also valid | Treat repeated singular value subspaces as a whole, not individual vectors |
| Forming explicitly for numerical work | Squares the condition number, losing precision in small singular values | Use bidiagonalization-based SVD routines (LAPACK) directly on |
| Truncating rank without checking the singular value spectrum ("scree") | Arbitrary can under- or over-fit the structure | Plot or cumulative energy and choose an elbow/threshold |
| Using full dense SVD on huge sparse matrices | is infeasible at web scale | Use randomized or Krylov-subspace (Lanczos) truncated SVD methods |
Pioneers & history
The SVD's development spans nearly a century of differential geometry and numerical analysis, culminating in the algorithm that made it computationally practical for real matrices at scale.
Origins · 1 minEugenio Beltrami and how this was discovered
Where this matters
Recommender systems. Matrix factorization methods for collaborative filtering — famously used in the Netflix Prize competition — are directly inspired by truncated SVD: user and item latent factor matrices approximate a sparse ratings matrix as a low-rank product, letting the system predict unseen ratings.
Latent Semantic Analysis (LSA) / information retrieval. Applying SVD to term-document matrices reveals latent semantic dimensions, letting search engines and document-similarity systems match on meaning rather than exact keyword overlap.
Image and signal compression. Treating an image as a matrix of pixel intensities, truncating its SVD to a small rank reconstructs a visually similar image using far fewer numbers than the original ( versus ), illustrating the Eckart–Young guarantee directly.
Noise reduction and data denoising. Because noise tends to spread energy across many small singular values while true signal concentrates in the top few, truncating the SVD often removes noise while preserving structure — used in genomics (gene expression matrices), sensor arrays, and finance (covariance matrix denoising).
Numerical linear algebra infrastructure. The Moore–Penrose pseudo-inverse, used to solve least-squares problems and ill-conditioned linear systems, is defined directly via the SVD: , where inverts the nonzero singular values. This underlies ridge regression solvers, `numpy.linalg.pinv`, and robust regression pipelines throughout scientific computing.
Foundation for PCA and beyond. Every standard PCA implementation (`sklearn.decomposition.PCA`, R's `prcomp`) computes its result via SVD of the centered data matrix rather than by eigendecomposing the covariance matrix directly, for the same numerical-stability reasons discussed above. This also sets the stage for Manifold Learning methods, which relax SVD's linear-subspace assumption to model curved, nonlinear data geometry.
Ask the tutor: How does randomized SVD achieve near-optimal low-rank approximation without computing the full decomposition?
Is SVD the same thing as PCA?
Not quite — they are closely related but not identical. PCA is a statistical method for finding directions of maximum variance in mean-centered data. SVD is a linear-algebraic factorization that applies to any matrix, centered or not. When you mean-center your data matrix and compute its SVD, the right singular vectors coincide exactly with the principal component directions, and the singular values relate to the explained variance via . So PCA is best understood as a specific application of SVD to centered data, and most software actually computes PCA by calling an SVD routine internally rather than eigendecomposing the covariance matrix directly.
Why does the SVD always exist, but eigendecomposition sometimes doesn't?
Eigendecomposition requires a square matrix that is diagonalizable, meaning it has a full set of linearly independent eigenvectors; defective matrices (like a Jordan block) or rectangular matrices simply have no such decomposition. SVD sidesteps this entirely by using two different orthonormal bases — one for the row space, one for the column space — rather than insisting on a single shared eigenbasis. Because is always symmetric positive semi-definite for any real matrix , the spectral theorem guarantees real nonnegative eigenvalues and a complete orthonormal eigenbasis, which is exactly the ingredient the SVD construction needs, regardless of the shape or invertibility of .
What does a singular value of zero actually mean?
A zero singular value means the corresponding right singular vector lies in the null space of : . The number of nonzero singular values equals the rank of . In practice, due to floating-point noise, "zero" singular values often appear as very small but nonzero numbers; a common convention is to treat any below some tolerance (relative to ) as numerically zero when computing rank or a pseudo-inverse, since including it would massively amplify noise (dividing by a near-zero value in ).
How do you choose the truncation rank k in practice?
The most common approach is to examine the singular value spectrum — plotting or cumulative squared energy against — and look for an "elbow" where values drop sharply, then flatten. A related quantitative rule sets so that a fixed fraction (say 90% or 95%) of total energy is retained. In supervised downstream pipelines, is sometimes chosen by cross-validation on the task's actual performance metric rather than by an unsupervised energy threshold, since the "best" rank for reconstruction is not always the best rank for prediction.
Can SVD handle matrices with missing entries, like a ratings matrix?
The classical SVD as presented here assumes a fully observed matrix; it cannot be applied directly when entries are missing, because is undefined without complete rows/columns. In practice, applications like recommender systems use matrix factorization algorithms that solve a regularized optimization problem — minimizing squared error only over observed entries plus a regularization term — using alternating least squares or stochastic gradient descent. These methods are inspired by and closely related to truncated SVD, and converge to a similar rank- factorization , but they are not literally computing the SVD of an incomplete matrix.
Why is SVD said to be a bridge to manifold learning?
SVD (and PCA) assumes the data's important structure lies on or near a linear subspace of low dimension — a flat, rank- hyperplane through the data. Many real datasets (images of a rotating object, handwritten digit strokes, biological trajectories) instead lie on a curved, nonlinear manifold, where a linear rank- approximation would badly distort distances and neighborhoods, even if the intrinsic dimensionality is genuinely low. Manifold learning methods such as Isomap, t-SNE, and UMAP generalize the goal of SVD — find a faithful low-dimensional representation — to nonlinear geometries, often by locally linearizing the manifold and stitching those pieces together, or by preserving neighborhood structure directly.
What is the relationship between SVD and the Moore–Penrose pseudo-inverse?
The Moore–Penrose pseudo-inverse generalizes matrix inversion to non-square or singular matrices, and it is defined directly from the SVD as , where is formed by taking the reciprocal of each nonzero singular value (and leaving zeros as zeros) and transposing the shape. This construction automatically produces the unique matrix satisfying the four Moore–Penrose conditions, and it gives the minimum-norm least-squares solution to even when is rank-deficient or rectangular. This is exactly why libraries like NumPy's `pinv` and ridge-regression solvers compute an SVD internally rather than attempting a direct matrix inversion.