Foundations to Frontier
Tests
D. Classical Machine Learning › D9 Dimensionality Reduction and Manifold Learning

Sparse PCA

Sparse PCA finds directions of high variance that involve only a few of the original variables, making components interpretable and, when the true structure is sparse, more accurate. Ordinary PCA loadings are dense: every variable gets some weight, and in high dimensions with few samples the leading eigenvector is badly estimated. Sparse PCA adds a constraint or penalty on the number (or absolute size) of non-zero loadings, through methods such as the truncated power method, penalised matrix decomposition, SCoTLASS, or an elastic-net regression view. This page covers the spiked covariance model, why PCA fails when d ≫ n, the sparse formulations and algorithms, the variance–sparsity trade-off, the role of initialisation, and computational limits. In the exercises you implement the truncated power method and recover a planted sparse component; then you measure how sample size governs recovery for PCA and sparse methods.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Components you can explain

PCA components mix all your variables: “0.21 × temperature − 0.08 × pressure + 0.13 × …” across hundreds of sensors. That is hard to interpret, and with few samples many of those small weights are just noise. Sparse PCA looks for directions that capture a lot of variance while using only a handful of variables, giving components like “these 6 vibration channels move together”, which an engineer can act on.

Sparse PCA: components that use only a few variables
ordinary PCAsparse PCA, s = 6
|cos| with the true component: PCA 0.858 · sparse 0.976 · variance captured: PCA 5.47 · sparse 4.53
The shaded block marks the 6 variables that really carry the shared factor. With small n, the PCA eigenvector puts noticeable weight on noise variables, making it harder to interpret and less accurate. Sparse PCA forces all but s loadings to zero: with s near the true 6 (and n not tiny) it picks out the right variables and points closer to the truth, while capturing slightly less sample variance, the price of sparsity. Too small an s drops real variables (try 3), and with s = 40 it is ordinary PCA. With very few samples (n = 15) neither method can find the component.
Why engineers care

In spectroscopy, genomics and wide sensor arrays, the meaningful patterns typically involve a small subset of channels. Sparse components point straight to those channels: which wavelengths, which genes, which sensors. When samples are scarce relative to variables, they also estimate the true pattern better than dense PCA.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Sparse PCA components have…
  2. 2. Compared with PCA, sparse components capture…
  3. 3. Sparse PCA helps most when…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

The building blocks by hand

Hard truncation. Keep the s largest-magnitude entries and zero the rest. With s = 2, (0.1, −3, 2, 0.5) becomes (0, −3, 2, 0).

Soft thresholding (used in ℓ₁-penalised methods): sign(v)·max(|v| − λ, 0). With λ = 1, (3, −0.5, −2, 1) becomes (2, 0, −1, 0).

One truncated-power step. Take S = [[4, 1, 0], [1, 3, 0], [0, 0, 1]] and v = (1, 1, 1). Then Sv = (5, 4, 1); keep the top 2 entries to get (5, 4, 0), and normalise to (5, 4, 0)/√41.

The variance–sparsity trade-off. For S = [[4, 1], [1, 3]]:

  • the 1-sparse direction (1, 0) captures 4;
  • the dense direction (1, 1)/√2 captures 4.5;
  • the best dense direction (PCA) captures (7 + √5)/2 ≈ 4.62.

Sparsity costs variance, unless the truth is sparse.

The steps in plain English (truncated power method):

  1. Compute the sample covariance S and start from the leading PCA eigenvector (or another good start).
  2. Multiply by S, keep the s largest-magnitude entries, and normalise.
  3. Repeat until the vector stops changing.
  4. For more components, deflate (remove the found component from S) and repeat. Choose s by cross-validation, interpretability, or a variance target.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Truncating (4, −1, 0.5, −6) to s = 2 gives…
  2. 2. Soft threshold of 0.4 with λ = 1?
  3. 3. Variance captured by (0, 1) for S = [[4, 1], [1, 3]]?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.

Why PCA fails when d is large, and what sparsity buys

The spiked model. Σ = I + βvvᵀ, with v the true component.

  • When d/n does not shrink, the leading sample eigenvector is inconsistent: its cosine with v stays below 1, and it is essentially random if β < √(d/n), the BBP threshold.
  • If v has only s non-zeros, sparse estimators can succeed with about s² log d samples instead of d (Johnstone and Lu, 2009; Amini and Wainwright).

Exercise 1 (d = 50, a 5-sparse component, n = 300):

  • the truncated power method recovered the exact support, with |cos| 0.996 against 0.973 for the dense PCA eigenvector;
  • it captured slightly less sample variance (3.89 against 4.02).

Methods.

  • Truncated power (Yuan and Zhang, 2013) iterates with hard truncation.
  • Penalised matrix decomposition (Witten, Tibshirani and Hastie, 2009) uses soft thresholding.
  • SCoTLASS (Jolliffe et al., 2003) puts an ℓ₁ constraint on the loadings.
  • SPCA (Zou, Hastie and Tibshirani, 2006) regresses PCs on variables with an elastic net.
  • Diagonal thresholding (Johnstone and Lu) first keeps the highest-variance variables, then does PCA on them.

Initialisation matters. These are non-convex problems. Starting from the PCA eigenvector works when PCA is already roughly right. Below the detection threshold, every method fails. In exercise 2, at n ≤ 50, all methods had |cos| ≈ 0.2.

from sklearn.decomposition import SparsePCA
sp = SparsePCA(n_components=3, alpha=1.0, random_state=0).fit(X)    # ℓ₁ penalty; larger alpha → sparser
(sp.components_ != 0).sum(1)                                        # non-zeros per component
🐍 Exercise 1: truncated power method
Implement hard truncation and the truncated power method; on a spiked covariance with a 5-sparse component, recover the support, compare accuracy with the PCA eigenvector, and check the variance trade-off and the s = d limit.
📝 Quick check (Level 2)
0/3 answered
  1. 1. In the spiked model, PCA's leading eigenvector is essentially random when…
  2. 2. Sparse estimators can need about how many samples?
  3. 3. Why does initialisation matter for sparse PCA?

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Formulation. Maximise vᵀSv subject to ‖v‖₂ = 1 and ‖v‖₀ ≤ s. This is NP-hard in general, since it contains sparse regression and clique-type problems. Convex relaxations exist, such as the semidefinite program of d’Aspremont et al. (2007): maximise tr(SX) − ρ‖X‖₁ with X ⪰ 0 and tr(X) = 1. They are statistically good but computationally heavy for large d.

A statistical–computational gap. Information-theoretically, about s log d samples suffice to detect a sparse spike. Known polynomial-time methods need about s² log d. Under the planted-clique conjecture this gap cannot be closed (Berthet and Rigollet, 2013), a classic example of a statistical–computational trade-off.

Deflation and orthogonality. Sparse components found one at a time are generally not orthogonal, and their scores are correlated. “Variance explained” must then be computed jointly (adjusted variance), not by summing per-component values.

Interview questions.

  • When should you use sparse PCA instead of PCA? When interpretability matters, when variables are many and samples few, or when you believe a few variables drive each pattern.
  • How do you choose the sparsity? Cross-validate a reconstruction or downstream metric, check the stability of the selected variables across bootstrap samples, or set it by what an analyst can interpret.
📝 Quick check (Level 3)
0/3 answered
  1. 1. Exact ℓ₀-constrained sparse PCA is…
  2. 2. Sparse components found by deflation are generally…
  3. 3. The planted-clique conjecture implies…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

How many samples does sparsity save?

History.

  • I. Jolliffe, N. Trendafilov and M. Uddin proposed SCoTLASS (2003).
  • H. Zou, T. Hastie and R. Tibshirani gave SPCA via the elastic net (2006).
  • A. d’Aspremont et al. proposed a semidefinite relaxation (2007).
  • I. Johnstone and A. Lu (2009) analysed consistency in high dimensions.
  • X.-T. Yuan and T. Zhang introduced the truncated power method (2013).
  • Q. Berthet and P. Rigollet (2013) established the computational lower bound.

Exercise 2. Spiked model in d = 200 dimensions, a 10-sparse component with spike β = 2, 5 datasets per n. Each cell shows |cos| with the truth and the fraction of the true support among the 10 largest loadings.

n PCA truncated power (s known) truncated power (2s) diagonal thresholding
25 0.232, 0.22 0.228, 0.20 0.221, 0.22 0.147, 0.18
50 0.225, 0.20 0.203, 0.18 0.222, 0.18 0.122, 0.16
100 0.497, 0.62 0.708, 0.66 0.642, 0.66 0.482, 0.36
200 0.581, 0.76 0.853, 0.84 0.867, 0.96 0.423, 0.28
400 0.850, 1.00 0.992, 1.00 0.951, 1.00 0.834, 0.72
  • Below a sample-size threshold, nothing works. At n = 50, β = 2 sits exactly at the PCA detection threshold √(d/n) = 2, and the truncated power method, started from the PCA vector, inherits its failure.
  • Above it, sparsity pays clearly. At n = 200 the sparse estimate had |cos| 0.85–0.87 against 0.58 for PCA, and at n = 400, 0.99 against 0.85. Over-estimating s by a factor of 2 cost little.
  • Diagonal thresholding was weakest here. The spike adds only β/s = 0.2 to each true variable’s variance, too little to stand out from sampling noise in single variances.
🐍 Exercise 2 (research): sample size and sparse recovery
In a spiked model (d = 200, 10-sparse component), compare the PCA eigenvector, the truncated power method (s and 2s) and diagonal thresholding by cosine with the truth and support recovery for n from 25 to 400.

Sparse PCA in AI, robotics and aerospace

  • Spectral analysis: identifying the few wavelengths that carry a material’s or gas’s signature.
  • Wide sensor arrays: finding small groups of channels that co-vary, pointing to a subsystem.
  • Interpretable features for downstream models in safety-critical settings.

References

  1. H. Zou, T. Hastie, R. Tibshirani (2006). “Sparse principal component analysis.” Journal of Computational and Graphical Statistics 15(2).
  2. X.-T. Yuan, T. Zhang (2013). “Truncated power method for sparse eigenvalue problems.” JMLR 14.
  3. I. M. Johnstone, A. Y. Lu (2009). “On consistency and sparsity for principal components analysis in high dimensions.” JASA 104(486).
  4. D. M. Witten, R. Tibshirani, T. Hastie (2009). “A penalized matrix decomposition, with applications to sparse principal components and canonical correlation analysis.” Biostatistics 10(3).
  5. Q. Berthet, P. Rigollet (2013). “Optimal detection of sparse principal components in high dimension.” Annals of Statistics 41(4).