Nugget: PCA as a change of basis
Captured ahead of reading. This is a nugget — an application sketched before reaching the chapter, on hearing how PCA gets used. It has not been checked against §10.2–§10.3 yet, and the numbers come from
scripts/explore_nugget_pca.py, not from the book. Treat it as a pointer, not as verified notes.
The nugget
PCA is not “delete some columns”. It is the same change of basis idea as 2.2 Matrices, applied to data: keep every colour, but re-express the data on new axes chosen so that the first axis carries as much of the variation as possible, the second carries as much of what is left, and so on.
Then — and only then — you throw away the last axes, because by construction they carry almost nothing but noise.
The payoff is that you can compress, denoise and visualise data without losing the signal, and the new axes often turn out to be interpretable summaries that nobody explicitly programmed:
That is the “nugget” worth scribbling down: the axes PCA finds are frequently the business questions you would have asked anyway, discovered rather than specified.
In practice
This is why PCA shows up almost everywhere data has many columns:
- Compression and storage — keep the leading components and reconstruct approximately; the discarded directions are mostly measurement noise.
- Visualisation — project a space you cannot draw down to two or three dimensions that you can.
- Denoising — the small-variance directions are where the noise lives, so dropping them removes noise and keeps signal.
- A change of coordinates for modelling — a regression on components instead of raw columns can be far better conditioned, because the components are uncorrelated.
The scale of modern embeddings is the reason this is computed rather than drawn: word embeddings of a few hundred dimensions, image embeddings of or , and language-model representations in the thousands. None of them can be plotted. All of them can be rotated, because the arithmetic is identical to the 2-D case.
One honest caveat, which the worked example below demonstrates rather than hides: PCA finds directions of maximum variance, not causes. A component that explains a lot of variance may be a mixture of several real effects, and a small component may still be the one you care about. It is a compression tool that is sometimes interpretable — not an explanation engine.
Worked example
Fifty-two weeks of sales for five hairpin colours, built deliberately from three known latent effects plus noise:
- overall demand — all five colours move together;
- warm/cool mix — blue + lavender against red + green + yellow;
- yellow promotion — yellow on its own.
PCA is run on the data without being told any of that. Because the true effects are known (they generated the data), it is then possible to ask honestly whether PCA recovered them:
| Component | variance explained | cumulative | best-matching true effect (cosine) |
|---|---|---|---|
| PC1 | 69.2% | 69.2% | overall demand (0.995) |
| PC2 | 28.4% | 97.6% | warm/cool mix (0.955) |
| PC3 | 1.9% | 99.5% | yellow promotion (0.767) |
| PC4 | 0.2% | 99.8% | — |
| PC5 | 0.2% | 100.0% | — |
Two components carry 97.6% of the variance, so a 5-column problem collapses to 2 columns with 2.4% discarded. The loadings confirm what those two axes are — PC1 has all five colours with the same sign (everything moves together), while PC2 has blue + lavender opposing red + green + yellow:
| blue | lavender | red | green | yellow | |
|---|---|---|---|---|---|
| PC1 | |||||
| PC2 | |||||
| PC3 |
The interesting part is PC3. It matches the yellow promotion only partially (0.767), because yellow participates in both the warm/cool effect and the promotion. The third real effect is entangled with the second, so PCA cannot cleanly separate it — even though we, who built the data, know it is there. That is the caveat above, made concrete: PC1 and PC2 recovered the strong effects almost exactly, and PC3 did not.
All numbers above are produced by scripts/explore_nugget_pca.py.
References
- Deisenroth, Faisal & Ong, Mathematics for Machine Learning, §10.2 “Maximum Variance Perspective” and §10.3 “Projection Perspective”, with §4.5 (SVD) and §4.6 (Matrix Approximation) as the machinery underneath. (Material to read; not yet checked.) See References for the full citation and link.
- Reproducibility script:
scripts/explore_nugget_pca.py. - Related notes: 2.2 Matrices for the change-of-basis idea in its simplest form.