Singular Value Decomposition ā SVD (Linear Algebra)
SVD has a hidden generality that makes it the most quietly powerful tool in this whole series: eigenvalues and eigenvectors only exist for square matrices, but almost no real data matrix is square (more samples than features, or the reverse). SVD does something similar to eigen-decomposition, but for any matrix, any shape ā which is exactly why it, not eigen-decomposition, is what actually runs under the hood of PCA, recommender systems, and a large chunk of modern dimensionality reduction.
š” In one line: SVD breaks any matrix ā square or not ā into a rotation, a scaling, and another rotation, revealing its most important directions in order of importance, which is why it's the tool of choice for compressing and understanding real-world data.
The Decomposition
For any matrix A of shape (m, n), SVD writes it as:
A = U Ī£ Vįµ
- U ā an
(m, m)orthogonal matrix; its columns are the left singular vectors. - Ī£ ā an
(m, n)diagonal matrix of singular values,Ļā ā„ Ļā ā„ ... ā„ 0, always non-negative and sorted largest to smallest. - Vįµ ā an
(n, n)orthogonal matrix (transposed); its rows are the right singular vectors.
Geometrically: Vᵠrotates the input space, Σ stretches along the new axes by the singular values, and U rotates the result into the output space. Every linear transformation, no matter its shape, can be described this way.
How SVD Relates to Everything Before It
SVD isn't a separate idea from determinant, rank, and eigenvalues ā it's the decomposition that ties them together, generalized to non-square matrices:
| Concept | Connection to SVD |
|---|---|
| Rank | Rank of A = number of nonzero singular values |
| Eigenvalues | Singular values of A are the square roots of the eigenvalues of AįµA (or AAįµ) |
| Eigenvectors | For a symmetric matrix, singular values equal the absolute value of the eigenvalues, and singular vectors align with eigenvectors |
| Determinant | For a square matrix, ` |
| Pseudo-inverse | The pseudo-inverse A⺠is built directly from U, Σ, and Vᵠ|
This is why SVD generalizes eigen-decomposition rather than replacing it: for square symmetric matrices, the two coincide almost exactly; for everything else ā including every real dataset ā SVD is the one that's actually defined.
Low-Rank Approximation
The single most useful property of SVD: keeping only the top k singular values (and their corresponding vectors) gives the best possible rank-k approximation of A ā proven optimal by the Eckart-Young theorem. Small singular values contribute little to the matrix and can be dropped with minimal loss.
A ā Uā Ī£ā Vāįµ (using only the top k singular values)
This single idea ā "most of a matrix's information lives in its top few singular values" ā is the mechanism behind image compression, denoising, and dimensionality reduction all at once.
Where SVD Shows Up in AI
- PCA, done properly ā PCA is most commonly computed via SVD of the (centered) data matrix directly, rather than by explicitly forming the covariance matrix and eigen-decomposing it ā faster and numerically more stable.
- Recommender systems ā classic collaborative filtering factorizes a user-item ratings matrix via SVD (or SVD-like matrix factorization) to uncover latent taste/genre dimensions and predict missing ratings.
- Latent Semantic Analysis (LSA) ā applies SVD to a word-document matrix in NLP, uncovering latent topics as an early precursor to modern embeddings.
- Model compression ā large weight matrices in neural networks can be approximated with low-rank factors to shrink model size, the same underlying idea used in LoRA-style efficient fine-tuning.
- Noise reduction ā since noise tends to spread across many small singular values while real signal concentrates in the largest ones, truncating small singular values is a standard denoising technique.
Choosing How Much to Keep
Challenges
- Choosing
kā too few singular values loses real information; too many keeps noise and defeats the purpose of compression. A common approach is keeping enough to capture a target percentage of total variance (sum of squared singular values). - Cost on very large matrices ā full SVD is computationally expensive; truncated/randomized SVD algorithms compute only the top
kcomponents directly, without ever forming the full decomposition. - Sign ambiguity ā like eigenvectors, singular vectors have an arbitrary sign; don't read meaning into whether a component's values are mostly positive or negative.
- Confusing SVD with eigen-decomposition ā they coincide only for symmetric matrices; assuming singular values are eigenvalues for a general matrix is a common and incorrect shortcut.
Practical Notes
- Use
np.linalg.svd(A, full_matrices=False)for the compact form whenAisn't square ā avoids computing unnecessary extra dimensions. - For very large matrices, use randomized/truncated SVD (e.g.,
scikit-learn'sTruncatedSVD) rather than fullnp.linalg.svd, which computes the entire decomposition even if you only need the top few components. - Inspect the singular value spectrum before picking
kā a sharp drop-off is a strong signal for how much of the matrix is genuinely low-rank. - Prefer SVD over covariance eigen-decomposition for PCA in code ā it's the numerically standard approach and avoids explicitly forming
AįµA, which can amplify numerical errors.
Summary
- SVD factors any matrix, square or not, as
A = U Ī£ Vįµā rotate, stretch, rotate. - Singular values are sorted, non-negative, and directly connect to rank, eigenvalues, and determinant from earlier topics.
- The top-
ktruncation gives the provably best low-rank approximation ā the mechanism behind compression, denoising, and dimensionality reduction. - In AI, SVD powers PCA, recommender systems, LSA, and low-rank model compression techniques like LoRA.