Skip to content
mlmentorship

SVD and PCA

Separate singular directions of a linear map from principal directions of centered data, then choose rank using reconstruction error.

Published · 7 min read ·Core ·Foundation
Reading depth

Summary

SVD identifies input directions, output directions, and nonnegative scaling factors for any real matrix. PCA applies that decomposition to centered observations, retaining directions that minimize Euclidean squared reconstruction error. Large retained variance does not guarantee retained label information.

The decomposition

has . Full factors have orthogonal , orthogonal , and rectangular diagonal .

  • The first columns of span the row space; remaining columns span the nullspace.
  • The first columns of span the column space; remaining columns span the left nullspace.
  • Singular values satisfy ; rank counts strictly positive values in exact arithmetic.

The orthogonal factors can include reflections, not just rotations. For an invertible square map, the spectral condition number is . Null directions prevent unrestricted inversion; describes conditioning only on the retained nonzero subspace.

Truncated SVD and low-rank approximation

For rank at most , a best approximation in Frobenius or spectral norm is

Keep the leading singular values and their corresponding directions. Orthogonal changes of basis preserve these norms, reducing the error calculation to discarded diagonal entries:

Take omitted singular values as zero when none remain. This is the Eckart–Young result; a low-rank model constraint does not automatically prescribe truncating an unrelated matrix.

PCA as SVD

For observations in rows, fit a training mean and center .

  1. Decompose .
  2. Use leading columns as feature-space principal directions.
  3. Compute scores and reconstruct .
  4. Component sample variance is .

The covariance is ; its eigenvectors are these same principal directions. Direct SVD avoids explicitly forming a Gram matrix, which squares the nonzero singular-value condition ratio.

For an exact numerical companion to the schematic, use rows . They are centered, and , giving singular values and . Rank-one scores are ; reconstruct each second coordinate as zero. Four unit residuals give squared error , while retained variance is .

Keep the coordinate along PC1; discard the perpendicular reconstruction error

Keep one coordinate; discard the perpendicular residualProjecting (3,2) onto the horizontal first principal direction retains (3,0). The two-unit residual is reconstruction error, not another retained coordinate.Allowed fits lie on the green railObserved (3,2)Other tethers are longerShortest gap: perpendicularto the rail
Derivation
The retained coordinate stays; the perpendicular coordinate becomes reconstruction errorThe original six centered toy samples are drawn at PC coordinates (130,10), (-130,-10), (85,-20), (-85,20), (40,10), and (-40,-10). Orthogonal PC axes are rotated thirty degrees. Each circle connects perpendicularly to its diamond projection. The selected sample x equals 85 v1 minus 20 v2; a right-angle marker identifies the discarded residual. A separate one-dimensional axis draws all six PC1 scores and highlights the same scalar z=85, distinct from the reconstructed vector 85 v1. Cross-covariance is zero and PC1 variance is larger. Squared discarded coordinates sum to twelve hundred.Same six original toy samples; centered mean 0Circle: sample; diamond: rank-1 reconstructionx85 v1PC1: retainPC2: discard0THE SAME PC1 COORDINATES, ON ONE AXISz = 85-1500150z is one number; 85 v1 is a reconstructedvector.x = 85 v1 - 20 v2; discard only theperpendicular part.This error: 20^2 = 400. All six errors: 1200.
Read it this way: Follow the highlighted sample to scalar score z=85. Reconstruct the diamond at 85 v1. The perpendicular -20 v2 is discarded, giving squared error 400. These are illustrative coordinates, not measured data.
Check: Which object is the one-dimensional coordinate? How does it reconstruct the point on the PC1 line?
Read it this way: Projecting (3,2) onto the horizontal first principal direction retains (3,0). The two-unit residual is reconstruction error, not another retained coordinate.
Does the perpendicular displacement remain in the rank-one reconstruction?

Change the Requirement

Retain Ninety Percent of Variance

New task: Choose the smallest rank retaining at least of total squared singular-value mass.

Picture and change: Accumulate in descending order; change scores and reconstruction dimensions together.

Check: The fixture’s first component retains only ; rank two retains and reconstructs exactly.

Use when: A declared reconstruction requirement determines storage or representation size.

Standardize the Features

New task: Give both features equal sample variance before fitting PCA.

Picture and change: Divide centered columns by their training sample standard deviations, changing the feature-space metric.

Check: Fixture covariance becomes ; every unit direction is a possible first component, retaining .

Use when: Units or domain priorities justify equalized feature weighting. Carry the fitted mean, scales, and directions into inference; refitting on test data changes the transformation.

Common pitfalls

  • Different objective. Uncentered SVD includes the mean’s contribution; its leading direction need not equal the mean direction.
  • Automatic scaling. Standardization changes the objective and is undefined for zero-variance columns without a policy.
  • Whitening confusion. PCA scores are uncorrelated, not generally unit variance. Dividing by positive component standard deviations whitens them; zero singular values need exclusion or regularization.
  • Direction ambiguity. Singular-vector signs and tied-eigenvalue bases can vary without changing the reconstructed subspace.
  • Data geometry. Centering sparse matrices can destroy sparsity; categorical data need a justified metric.

Reconstruct

What if the label is the sign of the second feature?

The rank-one fixture discards that feature completely despite retaining eighty percent of variance. Unsupervised reconstruction quality is not a guarantee of predictive sufficiency.