Linear discriminant analysis
A generative linear classifier and supervised projection: Gaussian classes with a shared covariance.
Animated explanation
The idea
Logistic regression models the boundary directly. LDA takes the generative route: it assumes each class is a Gaussian cloud with its own mean but the same shape (covariance), estimates those clouds, and classifies a point by Bayes' rule: which cloud more probably produced it?
Because the clouds share a shape, the boundary comes out linear. The same mathematics also answers a geometric question first asked by Fisher in 1936: onto which direction should we project the data so that the classes are as separated as possible, relative to their spread? That makes LDA both a classifier and a supervised dimensionality reduction tool.
Fisher's projection
Projecting onto a direction turns each point into one number. A good direction pushes the projected class means apart and keeps each class tightly bunched. Fisher's ratio measures exactly that, and its maximiser is , where is the pooled within-class scatter matrix. Multiplying by tilts the direction away from axes along which the classes are stretched.
With classes, LDA finds up to such directions: a supervised alternative to PCA for visualisation.
LDA, QDA and logistic regression
- LDA (shared covariance) → linear boundaries, few parameters, works well with small data, but is hurt when the Gaussian assumption is badly wrong.
- QDA (one covariance per class) → quadratic boundaries, more parameters, needs more data.
- Logistic regression fits the same linear form without assuming Gaussians: more robust, slightly less efficient when the assumptions hold.
With many features and few samples, is singular; shrinkage LDA adds a multiple of the identity.
The algorithm, step by step
- 1Estimate class priors and class means .
- 2Compute the pooled covariance .
- 3Discriminant for class : .
- 4Predict .
The maths
Fisher criterion
Optimal direction
Discriminant function
Strengths and weaknesses
Strengths
- Closed form, no tuning, very fast
- Works well with small samples when classes are roughly Gaussian
- Doubles as supervised dimensionality reduction (K − 1 directions)
Weaknesses
- Assumes Gaussian classes with equal covariance
- Sensitive to outliers (means and covariances)
- Needs shrinkage when features outnumber samples
Reach for it when…
Check your understanding
Lambdian Lab
Fisher's discriminant
Two-class LDA from scratch.
- fisher_direction(X, y): , normalised to unit length.
- fit_lda(X, y): return (w, b) for the linear discriminant with equal-covariance Gaussians and class priors, so that class 1 is predicted when . Use the pooled covariance with denominator n − 2.
- predict(X, w, b).