Linear Algebra for Machine Learning

Singular Value Decomposition

Singular value decomposition as the rotate-stretch-rotate factorization of any matrix.

Lesson
10

Goal

Understand the singular value decomposition as a universal description of what a matrix does to space:

rotate or reflect, stretch independently along orthogonal axes, then rotate or reflect again.

By the end of the lesson, you should be able to read A=UΣVTA = UΣV^T as geometry rather than as a memorized factorization.

Motivation

Eigenvectors work beautifully for some matrices, but not for all matrices.

SVD is the stronger statement.

Every real matrix has an SVD, even if it is rectangular, singular, or awkward.

That is why SVD is one of the most useful theorems in applied linear algebra. It gives a common geometric language for compression, approximation, and dimensionality reduction.

Prerequisites

Notation / Symbol Table

SymbolPlain-English nameMeaning
AAmatrixThe linear map being decomposed.
UUleft orthogonal factorThe output-side orthogonal matrix.
ΣΣdiagonal singular-value matrixThe matrix of nonnegative stretch factors.
VTV^Tright orthogonal factorThe input-side orthogonal matrix transpose.
σiσ_isingular valueThe i-th nonnegative scale factor.
uiu_ileft singular vectorA column of UU.
viv_iright singular vectorA column of VV.

Core Ideas

The factorization

The singular value decomposition writes a matrix as

A=UΣVT.A = UΣV^T.

This is not just a bookkeeping trick.

It is a geometric description of the transformation.

The three stages

Think of the action on a vector in three steps:

  1. VTV^T changes coordinates into the matrix’s preferred input basis.
  2. ΣΣ stretches each coordinate independently.
  3. UU rotates or reflects the result into the output orientation.

That is the rotate-stretch-rotate picture.

The preferred basis is determined by the matrix itself, not chosen arbitrarily.

Why the middle matrix is diagonal

The singular values live on the diagonal of ΣΣ.

Because the matrix is diagonal in that middle basis, there is no mixing between coordinates there.

Each axis is scaled independently.

That is exactly the simplification we wanted.

Where the basis comes from

The columns of VV are the eigenvectors of ATAA^TA.

The columns of UU are the eigenvectors of AATAA^T.

Those matrices are symmetric, so their eigenvectors can be chosen orthonormal.

That orthogonality is what makes the decomposition clean.

Why the squares matter

In PCA and related “variance explained” calculations, the important quantity is not σiσ_i but σi2σ_i^2.

Stretch by 10 does not mean “10 times more energy.” It means “100 times more squared energy.”

So if the singular values are 100100, 2020, and 11, the relative contributions are proportional to

1002,202,12.100^2,\quad 20^2,\quad 1^2.

That is the correction that makes PCA and SVD line up with variance.

Worked Example

Start with the simple diagonal matrix

A=[5002].A = \begin{bmatrix} 5 & 0 \\ 0 & 2 \end{bmatrix}.

In this case, the SVD is especially simple:

U=I,Σ=[5002],VT=I.U = I,\qquad Σ = \begin{bmatrix} 5 & 0 \\ 0 & 2 \end{bmatrix},\qquad V^T = I.

The matrix just stretches the first axis by 5 and the second axis by 2.

If

x=[11],x = \begin{bmatrix} 1 \\ 1 \end{bmatrix},

then

Ax=[52].Ax = \begin{bmatrix} 5 \\ 2 \end{bmatrix}.

That example is simple, but it shows the meaning of the diagonal middle factor.

Now compare that with a rank-deficient case.

If

Σ=[5000],Σ = \begin{bmatrix} 5 & 0 \\ 0 & 0 \end{bmatrix},

then one direction is completely collapsed.

That means the transformation loses a dimension and cannot be inverted.

Energy share example

Suppose the singular values are 100100, 2020, and 11.

The squared values are

10000,400,1.10000,\quad 400,\quad 1.

Total energy:

10401.10401.

So the first component accounts for about 96.1%96.1\% of the energy.

That is why a rank-1 approximation can be so effective when one singular value dominates.

Why This Shows Up In ML

SVD shows up in:

PCA is especially close to SVD.

The singular vectors give the principal directions, and the squared singular values tell you how much variance each direction captures.

That makes SVD the practical engine behind many PCA implementations.

Common Confusions

Exercises

  1. Describe the three stages of the SVD in plain English.

  2. If Σ=diag(5,2)Σ = \operatorname{diag}(5, 2), what happens to a vector on each principal axis?

  3. What does a singular value of zero mean geometrically?

  4. Why are the eigenvectors of ATAA^TA orthogonal?

  5. If the singular values are 100100, 2020, and 11, what fraction of the energy does the first component capture?

Implementation Exercise

Write a TypeScript helper that computes how much variance or energy each singular value contributes.

A useful shape is:

function singularValueEnergyFractions(singularValues: number[]): number[];
function cumulativeEnergy(singularValues: number[], k: number): number;

The implementation should:

That exercise reinforces the main SVD lesson: the squares are what matter for explained energy.

Reflection Questions

Next Lesson

Next: Principal Component Analysis.

The bridge is immediate: PCA uses the same geometry as SVD to find the directions of largest variance in data.