Create your own
Lesson illustration

Singular Value Decomposition and Low-Rank Approximation

Hello. In the previous lesson, eigendecomposition gave a clean description of a symmetric square matrix: rotate into its eigenvector coordinates, scale each coordinate by an eigenvalue, then rotate back.

Singular value decomposition (SVD) extends that idea to any real matrix, including rectangular matrices such as a data matrix with many examples and relatively few features. It will become a key mathematical tool behind compression, denoising, dimensionality reduction, and several low-rank techniques used in modern ML systems.

By the end of this lesson, you should be able to compute the SVD of a small matrix using eigendecomposition of , form a rank- approximation, and explain precisely why retaining the largest singular values is the best low-rank approximation under common error measures.


SVD: independent input and output directions

For any real matrix

the singular value decomposition is

where:

  • is orthogonal. Its columns are the left singular vectors.
  • is orthogonal. Its columns are the right singular vectors.
  • is diagonal in the rectangular sense: entries may be nonzero only along its leading diagonal.
  • The diagonal entries of are the singular values:

where .

Unlike eigenvalues, singular values are always nonnegative.

To interpret the transformation, read the product from right to left:

  1. expresses an input vector in the right-singular-vector basis.
  2. scales each resulting coordinate by a nonnegative singular value.
  3. expresses the result in the output space using left singular vectors.

This distinction between input directions and output directions is why SVD applies to rectangular matrices. A matrix may map an -dimensional input into an -dimensional output, so it needs two potentially different orthonormal bases.

Singular Value Decomposition (the SVD)

Watch “Singular Value Decomposition (the SVD)” from MIT OpenCourseWare for the connection between the eigendecomposition you just learned and the more general SVD.

Watch the factorization for the basic form A=U\Sigma V^{\top}. Then watch the comparison, which explains why SVD works for rectangular matrices whereas ordinary eigendecomposition does not. Finish with the derivation link, focusing on why A^{\top}A has eigenvalues equal to squared singular values.

The central relation is:

Since is symmetric and positive semidefinite, it has orthonormal eigenvectors and nonnegative eigenvalues. Comparing this equation with the symmetric eigendecomposition form shows that:

So:

  • is an eigenvector of , hence a right singular vector of ;
  • the corresponding eigenvalue is ;
  • therefore,

For each nonzero singular value, the matching left singular vector is

Equivalently,

This equation is worth remembering: the matrix sends a right singular direction to its corresponding left singular direction, scaling it by .


Computing an SVD for a small matrix

Consider the rectangular matrix

It has three rows and two columns, so ordinary eigendecomposition of itself is not available. But is square:

This is the same kind of symmetric matrix handled in the prior lesson.

Step 1: Find the right singular vectors

The eigenvalues satisfy

Thus,

The associated normalized eigenvectors are

Place them in the columns of :

Step 2: Convert eigenvalues into singular values

Because ,

The singular values are already in descending order, as required.

Step 3: Find the left singular vectors

Use

For the first vector:

Therefore,

For the second vector:

Since ,

For the compact, or thin, SVD, collect only the columns associated with nonzero singular values:

The thin SVD is therefore

The thin form is usually what you want in ML code: it omits orthonormal basis directions multiplied by zero singular values.

A careful shape check:

Also note the important truncated-matrix identity:

but generally

because is tall and has only columns. The product is instead a rank- projection matrix.


SVD as a sum of rank-one patterns

The most useful way to read an SVD is as a sum:

Each term

is a rank-one matrix.

The product is an outer product: it combines one output-direction vector with one input-direction vector to produce an entire matrix. The singular value determines the strength of that pattern.

For our example,

The first rank-one component is

The second component is

Adding them recovers :

The first term captures the larger shared structure across the two columns. The second, smaller term captures the contrast between them. This “dominant pattern plus correction patterns” interpretation is the foundation of low-rank approximation.

Singular Value Decomposition (SVD): Matrix Approximation

Watch “Singular Value Decomposition (SVD): Matrix Approximation” by Steve Brunton to see the rank-one expansion and why retaining the leading terms is not merely a heuristic.

Watch rank one pieces to connect each term \sigma_i\mathbf{u}_i\mathbf{v}_i^{\top} to an outer product. Then watch the truncation for the construction of a rank-k approximation. Finish with the guarantee for the Eckart-Young result: the truncated SVD is the optimal rank-constrained approximation.


Truncated SVD and low-rank approximation

Suppose the singular values are ordered from largest to smallest. The rank- truncated SVD keeps only the first rank-one terms:

In matrix form,

where:

  • contains the first left singular vectors;
  • contains the largest singular values;
  • contains the first right singular vectors as rows.
A rank-\(k\) approximation \(A_k\) of an \(m \times n\) matrix is stored and reconstructed through an \(m \times k\) left-singular-vector matrix, a \(k \times k\) diagonal singular-value matrix, and a \(k \times n\) right-singular-vector matrix.

Because the product passes through a -dimensional middle space,

For our example, the rank-one approximation is simply the first component:

It does not reproduce exactly. Its residual is

The approximation has deliberately discarded the second, weaker singular pattern.

Why keep the largest singular values?

The Eckart-Young theorem states that is the closest matrix to among all matrices with rank at most , under both the Frobenius norm and the spectral norm.

For the Frobenius norm,

the theorem says:

The squared error has a particularly useful form:

For the rank-one approximation in the example,

No other rank-one matrix can achieve a smaller squared Frobenius reconstruction error.

This is stronger than saying that SVD gives a convenient approximation. It gives the provably best approximation for the chosen rank and error measure.


What low rank means for ML data

A low-rank approximation is useful when a large matrix is governed by a relatively small number of shared patterns.

If is , storing every entry requires numbers. A rank- representation stores approximately

numbers instead. When

this can be much smaller than .

Common interpretations depend on what rows and columns mean:

Matrix interpretationLeft singular vectors Right singular vectors
Image matrixImage-side spatial patternsPixel-direction patterns
User-item interaction matrixUser patternsItem patterns
Document-term matrixDocument patternsTerm or topic-like patterns
Centered tabular data matrixExample scores along dominant directionsFeature directions

The orientation is not cosmetic. If rows are examples and columns are features, lives in feature space, while describes how individual examples express the retained patterns.

A common diagnostic before choosing is the fraction of squared singular-value mass retained:

A rapid drop in singular values suggests that a small rank may approximate the matrix well. A slow decline means a low-rank approximation will discard substantial structure.

Two practical cautions matter:

  • Small does not automatically mean noise. Tail singular components can contain rare classes, minority-group behavior, important edge cases, or real but subtle signals.
  • Data preprocessing affects the decomposition. For feature data, centering and often scaling decisions can substantially change which directions dominate. The connection to PCA will make this precise later.

PyTorch verification

In PyTorch, use torch.linalg.svd. It returns , a vector of singular values, and Vh, which is for real-valued matrices.

import torch

A = torch.tensor(
    [
        [1.0, 1.0],
        [0.0, 1.0],
        [1.0, 0.0],
    ]
)

# Thin SVD: U is 3 by 2, s has length 2, Vh is 2 by 2
U, s, Vh = torch.linalg.svd(A, full_matrices=False)

# Exact reconstruction
A_reconstructed = (U * s) @ Vh
assert torch.allclose(A, A_reconstructed)

# Rank-1 approximation
k = 1
A1 = (U[:, :k] * s[:k]) @ Vh[:k, :]

# Eckart-Young reconstruction error
squared_error = torch.linalg.matrix_norm(A - A1, ord="fro") ** 2
assert torch.allclose(squared_error, s[1] ** 2)

print(s)
print(A1)

torch.linalg.svd returns singular values in descending order, so slicing the first components gives the truncated SVD directly.

Do not expect the signs of U and Vh to match a handwritten solution. For any singular-vector pair, simultaneously replacing

and

leaves the rank-one term unchanged:

Verify the reconstruction and approximation error rather than comparing singular-vector signs.


Key takeaways

SVD decomposes any real matrix as

with orthonormal left and right singular vectors and nonnegative singular values. You can compute the right singular vectors from the eigendecomposition of , obtain singular values by square-rooting its eigenvalues, and calculate left singular vectors using

Most importantly, SVD writes a matrix as a sum of ordered rank-one patterns:

Keeping only the first terms produces

the best rank- approximation under common matrix norms. This is the mathematical reason low-rank methods can compress or simplify structured data while retaining its dominant patterns.

Next, you will shift from linear algebra to multivariable calculus: partial derivatives and gradients, the machinery that lets ML models determine how to change their parameters.

Can't find a good explanation? Sign up and we'll make it for you

Sign up