Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Summarise first, then regress
A spectrometer measures 120 wavelengths, but neighbouring wavelengths move together, so there are really only a handful of independent patterns. Regressing on all 120 numbers is unstable: the coefficients fight each other. Principal component regression first summarises the 120 numbers into a few principal components (the main patterns of variation; PCA is covered in D9), then fits an ordinary regression on those few summaries.
Spectra, hyperspectral pixels, sensor arrays and telemetry channels are highly correlated. PCR is a simple, fast, well-understood way to regress on them, and the components are often physically interpretable, such as a continuum level or an absorption band.
- 1. PCR first replaces the features by…
- 2. PCA ranks directions by…
- 3. In the demo, PCR with k = 1 fails when y depends on…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.PCR by hand
Centred data: x₁ = (2, −2, 1, −1), x₂ = (2, −2, −1, 1), y = (4, −4, 0.5, −0.5).
- Principal directions: v₁ = (1, 1)/√2 and v₂ = (1, −1)/√2.
- Scores: z₁ = (2√2, −2√2, 0, 0) and z₂ = (0, 0, √2, −√2). Their squared lengths are 16 and 4, so PC1 explains 16/20 = 80% of the variance.
- Regress y on z₁: γ₁ = z₁ᵀy/16 = 16√2/16 = √2.
- Map back: β = v₁γ₁ = (1, 1).
- With k = 2 (OLS): γ₂ = z₂ᵀy/4 = √2/4 adds v₂γ₂ = (0.25, −0.25), giving β = (1.25, 0.75).
Because the scores are orthogonal, each component’s coefficient is a separate one-variable regression. Adding a component never changes the earlier coefficients.
The steps in plain English:
- Centre (and usually standardise) the features.
- Compute the principal components (SVD of the centred X).
- Keep the first k component scores.
- Regress y on them by least squares.
- Map the k coefficients back to coefficients on the original features: β = V_k γ.
- Choose k by cross-validation, not by the explained-variance rule alone.
- 1. Why is regressing on PC scores easy?
- 2. PCR with k = p equals…
- 3. Coefficients on the original features are…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.The estimator
SVD form. Centre X = UΣVᵀ. Then β̂_PCR(k) = Σⱼ₌₁ᵏ vⱼ (uⱼᵀy)/σⱼ.
OLS is the same sum over all j. Ridge uses every direction but shrinks each one: β̂_ridge = Σⱼ vⱼ · σⱼ/(σⱼ² + λ) · (uⱼᵀy).
| Method | Factor applied to direction j |
|---|---|
| OLS | 1 |
| PCR | 1 if j ≤ k, else 0 (hard threshold) |
| Ridge | σⱼ²/(σⱼ² + λ) (soft, smooth) |
Scaling. PCA depends on the units of the features, so standardise them when they are in different units. Do not standardise spectra measured in the same units: the variances carry information.
Choosing k:
- Cross-validation on prediction error is the right default.
- “Keep 95% or 99% of the variance” or the elbow of the scree plot are unsupervised rules. They are fine for compression but can drop predictive directions (exercise 2).
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import GridSearchCV
pcr = make_pipeline(StandardScaler(), PCA(), LinearRegression())
search = GridSearchCV(pcr, {"pca__n_components": range(1, 21)}, cv=5, scoring="neg_mean_squared_error").fit(X, y)Use it when the features are many and highly correlated, possibly with p > n, and the response is related to the main modes of variation. Prefer PLS (D1.18) or ridge when the signal may lie in low-variance directions.
- 1. Ridge's factor on direction j is…
- 2. Features in different units should be…
- 3. The safest way to choose k is…
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.Bias, variance and the pitfall
Bias–variance. Write the true β in the principal basis as Σ θⱼvⱼ.
- Dropping direction j adds bias θⱼ²σⱼ² (its contribution to the fitted values) and removes variance σ²/σⱼ² (from the coefficient).
- So it is worth dropping direction j when θⱼ²σⱼ² is below σ²/σⱼ²: when the direction has little spread and little signal.
Jolliffe’s warning (1982). Nothing forces the response to load on the high-variance directions. Real examples show the low-variance components carrying the signal. Exercise 2 is one: a trace mineral with a weak spectral signature lies in the 6th component, which the 99% rule drops, making the prediction useless.
Degrees of freedom. PCR with k components has exactly k (+1) degrees of freedom. Ridge’s are Σ σⱼ²/(σⱼ² + λ). The two have similar prediction error in many studies (Frank and Friedman, 1993), with ridge slightly ahead and less sensitive to the choice of k.
Computation. One thin SVD, O(np·min(n, p)), gives the fit for every k at once. Cross-validation needs one SVD per fold.
Variants:
- supervised PCA (Bair et al., 2006) first screens the features by their correlation with y;
- kernel PCR for non-linear structure;
- functional PCR for curves.
Interview questions.
- PCR or PLS? PCR picks directions by var(Xv). PLS picks them by cov(Xv, y), so it never ignores a predictive direction just because it has low variance.
- Does PCR do feature selection? No. Every original feature gets a coefficient through V_k.
- 1. Dropping a low-variance direction removes variance proportional to…
- 2. Jolliffe (1982) showed that…
- 3. Degrees of freedom of PCR with k components (plus intercept)?
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Minerals from rover spectra
History.
- Hotelling (1933) introduced principal components.
- Kendall (1957) and Massy (1965) proposed regressing on them.
- Jolliffe (1982) cautioned against discarding low-variance components.
- Frank and Friedman (1993) compared PCR, PLS and ridge in chemometrics.
- PCR, alongside PLS, is a standard tool for calibrating near-infrared and Raman spectrometers, including planetary instruments.
Exercise 1. Two pairs of near-duplicate features (noise 0.01). OLS gives coefficients (1.45, 0.56, 2.31, −3.35): wild, with a sign flip within the second pair. PCR with k = 2 gives (1.006, 1.004, −0.518, −0.517), the true effects split evenly. The first two components explain 99.997% of the variance, and 5-fold CV picks k = 2.
Exercise 2: rover reflectance spectroscopy. Setup: 120 wavelengths, mixtures of 6 minerals on a shared continuum, 50 training spectra, 30 repetitions. The table shows the test RMSE of the target’s relative abundance (its standard deviation is 0.29), with the median k in brackets.
| Scenario | Min-norm least squares | PCR, 99%-variance rule | PCR, k by CV | Ridge, λ by CV |
|---|---|---|---|---|
| Major mineral | 0.0075 | 0.0113 (k = 6) | 0.0059 (k = 8) | 0.0062 |
| Trace mineral (12× weaker signal) | 0.093 | 0.308 (k = 5) | 0.083 (k = 13) | 0.090 |
- When the target drives a major mode, every regularised method is near-perfect.
- When the target is a trace mineral, the 99% rule keeps 5 components, drops the trace direction, and the prediction is worthless: an RMSE of 0.31 against a standard deviation of 0.29.
- Cross-validation sees the loss and keeps 13 components. PCR(CV) is then slightly better than ridge. The lesson: choose k by prediction error, not by variance explained.
PCR in AI, robotics and aerospace
- Spectroscopy: NIR, Raman and LIBS calibration on rovers and in labs.
- Hyperspectral imaging: regression on compressed pixel spectra.
- Telemetry: regressing a health indicator on many correlated sensor channels.
- Preprocessing: PCA before regression or classification to reduce noise and dimension.
References
- H. Hotelling (1933). “Analysis of a complex of statistical variables into principal components.” Journal of Educational Psychology 24.
- W. F. Massy (1965). “Principal components regression in exploratory statistical research.” JASA 60(309).
- I. T. Jolliffe (1982). “A note on the use of principal components in regression.” JRSS C 31(3).
- I. E. Frank, J. H. Friedman (1993). “A statistical view of some chemometrics regression tools.” Technometrics 35(2).
- T. Hastie, R. Tibshirani, J. Friedman (2009). The Elements of Statistical Learning, 2nd ed., section 3.5. Springer.