Worked examples — PCA via eigendecomposition and SVD
This page is the "hands dirty" companion to the parent PCA note. There we derived why eigenvectors of the covariance matrix are the directions of maximum variance. Here we run the machine on every kind of input it can meet — clean 2D data, data with zero variance in one direction, data where two directions tie, already-centered data, a real-world word problem, and an exam twist. If you skipped the parent, read its Step 1–4 first; everything below assumes you know these words:
Recall Vocabulary you must already own (click to check yourself)
centered data ::: original data with the mean subtracted, so the cloud sits at the origin covariance matrix ::: a symmetric table; diagonal = variances, off-diagonal = how features move together eigenvector / eigenvalue ::: a direction that only stretches (not rotates), and the stretch factor = variance along it principal component (PC) ::: an eigenvector of , ordered by its eigenvalue singular value ::: from SVD of the data matrix; connected by
If any of those are fuzzy, revisit Linear-Algebra-Eigenvalues-and-Eigenvectors and Linear-Algebra-SVD.
A note on characteristic polynomials
Every 2D example below solves . Rather than pull the coefficients "by inspection," here is the general rule we will reuse each time.
We cite this box every time so no coefficient appears unexplained.
The scenario matrix
Before working anything, let us list every distinct situation a PCA problem can be. A worked example is only useful if it covers a cell of this table that the others don't.
| # | Cell (the scenario) | What makes it different | Example |
|---|---|---|---|
| A | Generic tilted cloud, | the "normal" case, one clear dominant direction | Ex 1 |
| B | Axis-aligned data (off-diagonals ) | PCs are just the original axes — a sanity floor | Ex 2 |
| C | Degenerate: one direction has zero variance () | data lies on a perfect line; rank-deficient | Ex 3 |
| D | Isotropic tie () | no unique PC — direction is ambiguous | Ex 4 |
| E | Negative covariance (cloud tilts "down") | sign of off-diagonal flips the PC into a different quadrant | Ex 5 |
| F | Scaling matters (unscaled vs scaled features) | why we sometimes standardise first | Ex 6 |
| G | Real-world word problem (age vs heart-rate) | translate a story into , interpret the PC | Ex 7 |
| H | Exam twist: given eigenvalues, choose | reverse direction — pick dimensionality from EVR | Ex 8 |
We now hit each cell. Wherever geometry appears, look at the figure — the arrows are the argument.
Ex 1 — Cell A: the generic tilted cloud
Forecast: the points climb roughly along a line — guess PC1 points up-and-to-the-right, and captures almost all variance. Will be near the total?
The figure below plots the five data points (black dots) with the mean marked by a black cross; the red arrow is PC1, drawn from the mean along the direction that eigen-analysis will produce. Notice the arrow lies inside the elongated cloud — that is what "direction of maximum variance" looks like.

-
Center. Mean , so Why this step? PCA measures spread from the mean; if we don't move the cloud to the origin, PC1 would waste itself pointing at the mean.
-
Covariance with : Why this step? We need the object whose eigenvectors are the variance directions — that object is .
-
Eigenvalues via the template. Here , so trace and . Dropping these into the boxed formula: . Why this step? The eigenvalue is the variance along its direction (parent's Lagrange proof). Big = long axis.
-
Eigenvector for . Solve , normalise: . Why this step? This unit arrow is PC1 — the red arrow in the figure.
-
Project onto PC1: . Why this step? Each 2D point collapses to one number = its position along the long axis. We threw away only the tiny .
Verify: EVR of PC1 — 99.7% captured. Trace check: . ✓
Ex 2 — Cell B: axis-aligned data (sanity floor)
Forecast: if features are independent and axis-aligned, PCA should hand back the original - and -axes — no rotation. PC1 = whichever axis spreads more.
-
Center. , . Why this step? Same reason as always — variance is measured from the mean.
-
Covariance (): off-diagonal . Why this step? The zero off-diagonal is the whole point — it says the features are uncorrelated.
-
Eigenvalues/vectors. A diagonal matrix already displays its eigenvalues (the template gives , so factors as ): , with , . Why this step? Diagonal eigenvectors are the standard axes.
Verify: . ✓ PC1 is the -axis because spreads more (). This is the floor every PCA must respect: aligned data yields aligned PCs.
Ex 3 — Cell C: degenerate, zero-variance direction
Forecast: the cloud is a perfect line. There is genuinely nothing to see off that line — so should be exactly . PCA discovers the line is 1-dimensional.
The figure shows all four points lying exactly on a straight line; the red arrow is PC1, pointing along that line. There is no spread perpendicular to the arrow at all — that is why the second eigenvalue will be zero.

-
Center. , .
-
Covariance (): . Why this step? Notice the second row is exactly twice the first — the matrix is rank 1. That's the algebraic fingerprint of "data on a line."
-
Eigenvalues via the template. Here : trace and . So , giving . Why this step? A zero eigenvalue is not an error — it's the honest statement "zero variance in that direction" (which the zero determinant already forecast).
-
PC1 solves , exactly the line's direction. Why this step? PCA recovers the slope-2 line: the arrow lies on the data.
Verify: . ✓ EVR of PC1 . Reducing to loses nothing — this is the ideal compression.
Ex 4 — Cell D: isotropic tie (ambiguous PCs)
Forecast: the cloud looks the same in every direction (isotropic). There should be no unique winner — any direction has equal variance.
The figure plots the four points forming a plus/diamond shape, with a red circle drawn around them: the circle signals that every radial direction is equally "long," so no single arrow can claim to be PC1.

-
Center. Mean is already , so . Why this step? Always confirm — here centering is a no-op, but skipping the check is where bugs hide.
-
Covariance (): . Why this step? A scalar multiple of the identity is the algebraic sign of "same spread everywhere."
-
Eigenvalues via the template. Here : . A repeated root . For , every vector is an eigenvector. Why this step? The tie means PC1 is not defined — , , are all equally valid.
Verify: trace . ✓ EVR of any single PC .
Ex 5 — Cell E: negative covariance (down-tilting cloud)
Forecast: negative correlation the long axis runs upper-left to lower-right. PC1's two components should have opposite signs.
The figure shows the four points sloping downward left-to-right; the red arrow is PC1, running from lower-right to upper-left. Its horizontal and vertical components have opposite signs — that opposite-sign pattern is the visible fingerprint of negative covariance.

-
Center. , .
-
Covariance (): . Why this step? The negative off-diagonal is the number that will drag PC1 into the second/fourth quadrant.
-
Eigenvalues via the template. With : trace and . So Why this step? Same variance-finding as before; nothing about signs changes the method — only the value of .
-
PC1. Solve (opposite signs — points down-right). Why this step? The sign pattern is the whole lesson: negative covariance flips the arrow across the horizontal.
Verify: . ✓ The product of PC1's components is negative, confirming the down-tilt. Compare with Ex 1 where both were positive.
Ex 6 — Cell F: why scaling changes the answer
Forecast: height's numbers are ~30× bigger, so raw PCA's PC1 will point almost entirely along height. Standardising should let weight compete.
-
Raw center. . Centered height column is , weight .
-
Raw covariance (): , . Why this step? — height dominates purely because its units are larger.
-
Raw PC1 is essentially : it tracks height, ignoring weight almost entirely. Why this step? Shows the danger — PCA is not scale-invariant.
-
Standardise each column to unit variance (divide by its std). Now both variances equal , so becomes the correlation matrix with . Compute the cross term . Then Why this step? Standardising strips units so the pattern (correlation), not the magnitude, drives PCA.
-
Standardised eigenvalues via the template on : trace , , so , giving , with . Why this step? Now PC1 splits equally between height and weight — the honest joint direction.
Verify: (two standardised features). ✓ EVR of PC1 . See 2.4.03-Feature-Scalingand-Normalization — always standardise when units differ.
Ex 7 — Cell G: real-world word problem
Forecast: older members have lower heart-rate here — expect negative correlation, PC1 pointing "older + fitter." One number should summarise each member well.
-
Build and center. . Centered ages , HR . Why this step? Translating the story into a matrix is the real skill — rows = people, columns = measurements.
-
Covariance (): ; ; . Why this step? Negative covariance confirms our forecast: age up, HR down.
-
Eigenvalues via the template. : trace and . So
-
PC1 . Why this step? Interpret: moving along PC1 means age increases while heart-rate decreases — a single "aging-and-getting-fitter-here" axis.
Verify: . ✓ EVR — one number describes each member almost perfectly.
Ex 8 — Cell H: exam twist — choose from eigenvalues
Forecast: most variance is in the first two or three — guess .
-
Total variance . Why this step? is a fraction of the total, so we need the denominator first.
-
Cumulative EVR:
| cumulative | EVR | |
|---|---|---|
| 1 | 12 | 0.600 |
| 2 | 17 | 0.850 |
| 3 | 19 | 0.950 |
| 4 | 19.6 | 0.980 |
Why this step? We scan until the running fraction first reaches the threshold.
- Decide: at , EVR exactly — the first meeting the bar. Choose . Why this step? The rule "keep 95% of variance" (parent's Step-choosing section) picks the elbow automatically.
Verify: ✓ and , so is insufficient. is minimal.
Recall One-line summary of every cell
A generic cloud ::: , PC1 along the long axis Axis-aligned ::: off-diagonal , PCs are the original axes Data on a line ::: , rank-1 covariance, lossless to 1D Isotropic tie ::: , PC direction ambiguous Negative covariance ::: PC1 components have opposite signs Different units ::: standardise first or big-unit feature hijacks PC1 Word problem ::: rows = samples, columns = measurements, PC1 = dominant joint trend Choose ::: smallest with cumulative EVR
See also: Linear-Algebra-SVD for the numerically-safer route to these same PCs, 2.6.04-Kernel-PCA when a straight line can't capture the cloud, and 3.2.05-Autoencoders for the nonlinear generalisation. For clustering the projected data, 2.5.07-K-Means-Clustering. Foundations in 2.5.01-Introduction-to-Unsupervised-Learning.