Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Reduce dimensions without losing what tells classes apart
PCA keeps the directions where data spread most. But the direction that best separates “healthy” from “faulty” may be a quiet, low-variance one, and PCA could throw it away. Fisher LDA uses the labels. It finds directions where the class averages are far apart compared with how spread out each class is. With C classes it needs at most C − 1 dimensions, and the classes stay as separable as a linear projection allows.
For fault diagnosis and target recognition, you want a compact feature space that keeps classes apart, not one that keeps the most variance. Fisher discriminants give that: from hundreds of sensor features to C − 1 interpretable discriminant scores, often followed by a simple classifier. They are classic in spectroscopy, face recognition (Fisherfaces) and condition monitoring.
- 1. Fisher LDA uses…
- 2. With 5 classes, LDA gives at most…
- 3. If classes differ along a low-variance direction, PCA's first component…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.The Fisher criterion by hand
Scatter matrices.
- Within-class: S_w = Σ over classes of Σ over members (x − m_c)(x − m_c)ᵀ.
- Between-class: S_b = Σ over classes of n_c (m_c − m)(m_c − m)ᵀ.
1-D example. Class 0 at 0 and 2, class 1 at 4 and 6.
- Class means 1 and 5, overall mean 3.
- S_w = (1 + 1) + (1 + 1) = 4.
- S_b = 2·(1 − 3)² + 2·(5 − 3)² = 16.
- The Fisher ratio J = S_b/S_w = 4.
Two classes: w ∝ S_w⁻¹(m₁ − m₀). For class 0 at (0, 0), (1, 1), (0, 1) and class 1 shifted by (2, 0): S_w = [[4/3, 2/3], [2/3, 4/3]] and m₁ − m₀ = (2, 0), so w ∝ (2, −1)/√5. It is tilted away from the mean difference to avoid the within-class correlation.
Number of components. S_b is a sum of C rank-one terms constrained around the overall mean, so its rank is at most C − 1. For 10 classes in 784 dimensions: 9.
The steps in plain English:
- Compute the class means and the overall mean, and form S_w and S_b.
- Solve S_b w = λ S_w w (whiten by S_w, then take the eigenvectors of the whitened S_b), keeping the top C − 1 or fewer.
- Project the data onto these directions.
- Classify with the nearest class mean in the projected space, or feed the projection to another model. Regularise S_w if n is small relative to d.
- 1. S_b for class means 0 and 4 (2 points each), overall mean 2, in 1-D?
- 2. Fisher ratio for S_b = 12, S_w = 3?
- 3. Maximum LDA components for 3 classes in 100-D?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.Why it works, and what goes wrong with few samples
The eigenproblem. Maximising J(w) = wᵀS_b w / wᵀS_w w (a generalised Rayleigh quotient) gives S_b w = λS_w w. Whitening with S_w^(−½) turns it into an ordinary symmetric eigenproblem.
In the whitened space, within-class scatter is spherical, so Euclidean distance to class means equals Mahalanobis distance. Nearest class mean there is exactly the Gaussian classifier with shared covariance and equal priors (the LDA classifier).
Exercise 1 had classes separated only along a low-variance axis (standard deviation 0.5), next to a high-variance nuisance axis (5):
- along LDA’s first direction the Fisher ratio was 6.53, against 0.0087 along PC1;
- nearest class mean in the 2-D LDA space classified 92.3% correctly.
The small-sample problem. With n < d (or n barely above d), S_w is singular or badly estimated. The remedies:
- Pseudo-inverse.
- PCA first (to at most n − C dimensions), then LDA.
- Shrinkage: S_w ← (1 − λ)S_w + λ(tr S_w/d)I, with λ chosen, for example, by Ledoit–Wolf.
In exercise 2 (4 classes in 50-D):
- with 10 samples per class (40 < 50), Ledoit–Wolf shrinkage was best (0.49 against 0.36 for the pseudo-inverse);
- with 20 or more per class, plain LDA reached 0.996–0.999, while shrinkage hurt (0.70–0.97). Ledoit–Wolf targets covariance error, not discrimination, and shrinking toward the identity blurred the low-noise directions that carried the class signal.
PCA is the wrong tool here. Keeping C − 1 principal components gave about chance accuracy (0.29–0.31): the class signal was not in the high-variance directions.
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
lda = LinearDiscriminantAnalysis(n_components=2, solver="eigen", shrinkage=None).fit(X, y)
Z = lda.transform(X) # Fisher discriminant scores; shrinkage="auto" uses Ledoit–Wolf- 1. In the S_w-whitened space, nearest class mean equals…
- 2. With n < d, S_w is…
- 3. In exercise 2, with plenty of data, Ledoit–Wolf shrinkage…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Bayes optimality. For Gaussian classes with a shared covariance and equal priors, the Bayes classifier’s decision depends on x only through its projection onto the C − 1 Fisher directions. LDA reduction loses nothing for classification under that model. With unequal covariances (QDA settings), Fisher’s directions are not sufficient.
Ranks. rank(S_w) ≤ n − C and rank(S_b) ≤ C − 1. When n − C < d, S_w is singular, and there are directions with zero within-class scatter. The Fisher criterion is then infinite along any of them with non-zero between-class scatter, which is overfitting by construction. Regularisation or PCA-first fixes this.
Alternatives.
- Regularised discriminant analysis (Friedman, 1989) blends LDA and QDA covariances with shrinkage.
- Kernel Fisher discriminants give nonlinear versions.
- Neighbourhood components analysis and metric learning optimise classification directly.
Interview questions.
- PCA or LDA before a classifier? LDA if labels are available and classes are roughly Gaussian with similar spread. PCA when unsupervised compression is needed or labels are scarce. PCA → LDA is a standard combination for n < d.
- How do you choose the shrinkage? Ledoit–Wolf gives a fast covariance-optimal value, but for classification, cross-validate the shrinkage on accuracy. Exercise 2 shows the two can disagree.
- 1. rank(S_w) is at most…
- 2. LDA reduction is lossless for classification when classes are…
- 3. Regularised discriminant analysis blends…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.What to do when samples are scarce
History.
- R. A. Fisher (1936) introduced the linear discriminant on Anderson’s iris data.
- C. R. Rao (1948) extended it to multiple classes.
- J. Friedman (1989) proposed regularised discriminant analysis.
- P. Belhumeur, J. Hespanha and D. Kriegman (1997) introduced Fisherfaces (PCA then LDA).
- O. Ledoit and M. Wolf (2004) gave analytic shrinkage intensities.
Exercise 2. 4 classes in 50 dimensions with correlated within-class noise (class means only 0.3 apart per coordinate), 200 test points per class, 4 datasets. Values are nearest-centroid test accuracy in the reduced space (chance 0.25).
| samples per class | LDA (pseudo-inverse) | shrinkage LDA (Ledoit–Wolf) | PCA → LDA | PCA (k = C − 1) |
|---|---|---|---|---|
| 10 | 0.361 | 0.489 | 0.376 | 0.287 |
| 20 | 0.999 | 0.696 | 0.999 | 0.287 |
| 40 | 0.996 | 0.843 | 0.996 | 0.289 |
| 160 | 0.999 | 0.969 | 0.999 | 0.306 |
- With fewer samples than dimensions, every method struggled. Shrinkage helped most, but only to 0.49.
- Once n exceeded d, plain LDA was nearly perfect. Ledoit–Wolf shrinkage cost accuracy, because its covariance-error-optimal intensity blurs the informative low-noise directions. For classification, tune shrinkage by cross-validated accuracy instead.
- PCA to C − 1 dimensions stayed near chance. Variance and class separability were unrelated here.
Fisher discriminants in AI, robotics and aerospace
- Fault diagnosis: projecting many vibration or engine features onto C − 1 discriminants that separate fault types.
- Target and terrain classification from spectral signatures.
- Feature reduction before simple classifiers on embedded hardware, where C − 1 scores are cheap to compute.
References
- R. A. Fisher (1936). “The use of multiple measurements in taxonomic problems.” Annals of Eugenics 7(2).
- J. H. Friedman (1989). “Regularized discriminant analysis.” JASA 84(405).
- P. N. Belhumeur, J. P. Hespanha, D. J. Kriegman (1997). “Eigenfaces vs. Fisherfaces: recognition using class specific linear projection.” IEEE TPAMI 19(7).
- O. Ledoit, M. Wolf (2004). “A well-conditioned estimator for large-dimensional covariance matrices.” Journal of Multivariate Analysis 88(2).
- T. Hastie, R. Tibshirani, J. Friedman (2009). The Elements of Statistical Learning, §4.3. Springer.