Foundations to Frontier
Tests
D. Classical Machine Learning › D2 Linear Classifiers

Linear Discriminant Analysis (LDA)

Linear discriminant analysis classifies by modelling each class as a Gaussian with its own mean but a shared covariance, then applying Bayes' rule. Because the covariance is shared, the quadratic terms cancel and the decision boundaries are linear. It has closed-form estimates (class means, pooled covariance, priors), gives posterior probabilities, and doubles as Fisher's supervised dimensionality reduction to K − 1 dimensions. This page covers the generative model and discriminant functions, Fisher's criterion, the equivalence with least squares for two classes, shrinkage (regularised) LDA for small samples, and the classic comparison with logistic regression. In the exercises you implement LDA and Fisher's projection and check them against the Bayes classifier; then you separate satellites from meteors in a sky survey and compare LDA, shrinkage LDA and logistic regression with small samples and with non-Gaussian glints.

Level 0: Foundation

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

Describe each class, then ask Bayes

Instead of drawing a boundary directly, LDA first describes each class: “satellite tracks are centred here, meteors there, and both scatter in the same elliptical way.” For a new track it asks which description makes it more likely (allowing for how common each class is) and picks that class. Because both classes share the same elliptical spread, the dividing line comes out straight.

LDA: shared ellipses, straight boundary
projection onto w = Σ⁻¹(μ₁ − μ₀)
w = (2.89, -1.59) · training error on these points 15.8% · log prior ratio shifts the threshold by 0.00
Dashed: the line joining the means. With correlated features the best boundary is tilted relative to the bisector, because w = Σ⁻¹(μ₁ − μ₀) accounts for the shared spread. Making a class rarer moves the boundary toward it, trading its recall for fewer false alarms.
Why engineers care

LDA is fast (closed form), works well with small labelled sets, gives probabilities, and its projection to K − 1 dimensions is a compact, interpretable feature reducer. These are reasons it remains common in sensor classification, BCI (brain–computer interfaces), and spectral and hyperspectral analysis.

📝 Quick check (Level 0)
0/3 answered
  1. 1. LDA models each class as…
  2. 2. LDA's decision boundaries are…
  3. 3. In the demo, making orange rarer moves the boundary…

Level 1: Beginner

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

LDA in one dimension

Class A ~ N(0, 1) and class B ~ N(2, 1).

Equal priors. Classify as B when the B density times its prior exceeds A’s. With a shared variance this becomes a linear rule:

  • δ_B(x) − δ_A(x) = x·(2 − 0) − ½(4 − 0) + log(π_B/π_A) = 2x − 2 + log(π_B/π_A);
  • with π_A = π_B, the boundary is x = 1, halfway between the means.

Rare class B (π_B = 0.2). The boundary solves 2x − 2 + log(0.25) = 0, giving x = 1 + 0.693 = 1.693. The boundary moves toward the rare class, so we need stronger evidence before calling B.

Estimating from data. Use the class means, the class proportions as priors, and the pooled variance. For values A = 0, 2 and B = 10, 12, the within-class sum of squares is 2 + 2 = 4. Divided by n − K = 2, the pooled variance is 2.

The steps in plain English:

  1. Estimate each class’s mean and prior (its share of the training data).
  2. Estimate one covariance matrix pooled over all classes (the within-class spread).
  3. For a new point, compute each class’s discriminant score xᵀΣ⁻¹μₖ − ½μₖᵀΣ⁻¹μₖ + log πₖ.
  4. Predict the class with the highest score. The softmax of the scores gives posterior probabilities.
  5. Optionally project onto the top K − 1 Fisher directions to visualise or compress.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Boundary for N(0, 1) vs N(4, 1), equal priors?
  2. 2. Making class B rarer moves the boundary…
  3. 3. The pooled covariance divides the within-class scatter by…

Level 2: Intermediate

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

The model

Generative model: P(y = k) = πₖ and x | y = k ~ N(μₖ, Σ).

Log-posterior up to a constant: log πₖ − ½(x − μₖ)ᵀΣ⁻¹(x − μₖ). The xᵀΣ⁻¹x term is common to all classes and cancels, leaving the linear discriminant

δₖ(x) = xᵀΣ⁻¹μₖ − ½μₖᵀΣ⁻¹μₖ + log πₖ.

Two classes: predict 1 when wᵀx + b > 0, with w = Σ⁻¹(μ₁ − μ₀) and b = −½(μ₀ + μ₁)ᵀw + log(π₁/π₀). So P(y = 1 | x) = σ(wᵀx + b): the posterior has exactly the logistic form.

Fisher’s criterion. Choose w to maximise the separation of the projected means relative to the projected spread: (wᵀ(μ₁ − μ₀))²/(wᵀS_W w). The maximiser is again w ∝ S_W⁻¹(μ₁ − μ₀). For K classes, the top K − 1 eigenvectors of S_W⁻¹S_B give the discriminant subspace.

Shrinkage LDA. With p comparable to n, the pooled covariance is noisy or singular. Use Σ̂ = (1 − α)S + α(tr S/p)I, with α chosen analytically (Ledoit–Wolf) or by CV.

from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
lda = LinearDiscriminantAnalysis(solver="lsqr", shrinkage="auto").fit(X, y)     # Ledoit–Wolf shrinkage
lda.predict_proba(X_new); Z = LinearDiscriminantAnalysis(n_components=2).fit(X, y).transform(X)   # Fisher projection

Use it when the classes are roughly Gaussian with similar spreads, the samples are small, or you want fast probabilities and a supervised low-dimensional projection. Prefer logistic regression when the class distributions are far from Gaussian (outliers, mixtures, discrete features), and QDA (D2.29) when the covariances differ.

🐍 Exercise 1: LDA and Fisher's directions
Implement LDA (class means, priors, pooled covariance), its discriminant functions and posterior probabilities, and Fisher's discriminant directions; on three Gaussian classes check the estimates, that the posteriors and accuracy match the true Bayes classifier, and that the 2-D Fisher projection separates the classes.
📝 Quick check (Level 2)
0/3 answered
  1. 1. For two classes, LDA's direction w is…
  2. 2. LDA's two-class posterior has the form…
  3. 3. How many useful Fisher directions are there for K classes?

Level 3: Advanced

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

LDA versus logistic regression

The same boundary family, different fitting. Both produce linear log-odds. LDA estimates them through the joint model P(x, y): means and covariance from all points. Logistic regression fits P(y | x) directly, mostly from points near the boundary.

Efficiency (Efron, 1975). If the Gaussian assumptions hold, LDA is more efficient: logistic regression needs about 30–100% more data for the same excess error when the classes are well separated. With moderate overlap, the gap is small. In exercise 2 the two are tied for n ≥ 40.

Robustness. LDA’s means and covariance use every point, including points far from the boundary. A few outliers or a non-Gaussian tail, even on the “easy” side, shift the means and inflate Σ, which tilts and moves the boundary. Logistic regression gives far, correctly classified points almost no weight. In exercise 2, 15% easy glints raised LDA’s error by 5–8 points, while logistic regression did not change.

Generative versus discriminative (Ng and Jordan, 2002). Generative models approach their asymptotic error with O(log p) samples, discriminative ones with O(p). So generative models win with little data, and discriminative models win asymptotically when the model is misspecified.

Regularisation:

  • shrinkage LDA (Ledoit–Wolf);
  • diagonal LDA (naive-Bayes-like, D3.31);
  • regularised discriminant analysis (Friedman, 1989), which interpolates between LDA and QDA.

Interview questions.

  • When does LDA beat logistic regression? With small samples and approximately Gaussian classes with equal covariances.
  • Why can LDA reduce to K − 1 dimensions without losing classification information? The class means span at most a (K − 1)-dimensional affine subspace in the whitened space, and the discriminants depend only on distances within it.
📝 Quick check (Level 3)
0/3 answered
  1. 1. Efron (1975) showed that under Gaussian classes LDA is…
  2. 2. Far but correctly classified outliers hurt…
  3. 3. Ledoit–Wolf shrinkage pulls the covariance toward…

Level 4: Expert

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

Satellites or meteors?

History.

  • Fisher (1936) introduced the linear discriminant for Anderson’s iris measurements.
  • Rao (1948) extended it to several classes.
  • Efron (1975) compared its efficiency with logistic regression.
  • Friedman (1989) introduced regularised discriminant analysis.
  • Ledoit and Wolf (2004) gave the analytic shrinkage used in modern LDA.
  • LDA remains a standard classifier for EEG-based brain–computer interfaces and a standard projection in chemometrics.

Exercise 1. Three Gaussian classes in 3-D with n = 6000. The estimated means, covariance and priors are within 0.08 of the truth. LDA’s accuracy is 0.8468, against 0.8455 for the true Bayes classifier. The Fisher eigenvalues are 2.03 and 0.37, and the 2-D projection separates all three class means.

Exercise 2: satellites versus meteors. Setup: 10 track features, 30 repetitions per size, test on clean tracks. The table shows test error.

Scenario, tracks per class LDA Shrinkage LDA Logistic regression
Gaussian, 15 0.328 0.319 0.330
Gaussian, 40 0.287 0.287 0.288
Gaussian, 200 0.259 0.259 0.259
15% easy glints, 15 0.405 0.351 0.331
15% easy glints, 40 0.353 0.331 0.285
15% easy glints, 200 0.307 0.306 0.262
  • When LDA’s assumptions hold, all three are essentially tied, apart from a small gain from shrinkage at n = 15, where the 10×10 pooled covariance is noisy.
  • Glints that are easy to classify still wreck LDA: they drag the satellite mean outward and inflate the covariance. Error rises by 5–8 points, and more data does not fix it, because the estimate is biased.
  • Logistic regression is untouched (0.262 against 0.259 without glints). It fits the boundary, not the clouds.
🐍 Exercise 2 (research): LDA, shrinkage LDA and logistic regression
Simulate 10-feature satellite and meteor tracks (Gaussian with shared covariance, or with 15% far 'glints' on the satellite side); compare LDA, Ledoit–Wolf shrinkage LDA and L2-penalised logistic regression by clean test error for 15, 40 and 200 training tracks per class.

LDA in AI, robotics and aerospace

  • Brain–computer interfaces: shrinkage LDA on EEG features is a standard decoder.
  • Spectral and hyperspectral classification: Fisher projections reduce many bands to a few discriminant axes.
  • Sensor fault classification with few labelled faults.
  • Feature extraction: supervised projection before k-NN or clustering.

References

  1. R. A. Fisher (1936). “The use of multiple measurements in taxonomic problems.” Annals of Eugenics 7(2).
  2. B. Efron (1975). “The efficiency of logistic regression compared to normal discriminant analysis.” JASA 70(352).
  3. J. H. Friedman (1989). “Regularized discriminant analysis.” JASA 84(405).
  4. O. Ledoit, M. Wolf (2004). “A well-conditioned estimator for large-dimensional covariance matrices.” Journal of Multivariate Analysis 88(2).
  5. A. Y. Ng, M. I. Jordan (2002). “On discriminative vs. generative classifiers: a comparison of logistic regression and naive Bayes.” NeurIPS.