Linear Discriminant Analysis: Derivation, Intuition, and a Real Failure
1. Recall PCA
Start with observations . Center them by subtracting the sample mean . Define the scatter matrix:
PCA asks: along which unit vector does the projected data have the most spread? The projected variance is
(verify by expanding ). We constrain to fix the scale, giving the constrained optimization:
Introduce a Lagrange multiplier and form:
Setting :
The optimum is an eigenvector of . The objective value at the optimum is , so the maximum projected variance equals the eigenvalue. PC1 is the eigenvector corresponding to the largest eigenvalue; PC2, the second largest; and so on.
Closed-form solution in two dimensions
When and , the characteristic equation gives:
The eigenvector for satisfies , so it is proportional to — normalise to get a unit vector. PC2 is perpendicular.
The widget below uses exactly this formula, updated after every click.
Note what this derivation did not use: class membership. The labels appear nowhere. PCA maximizes spread; it is blind to which observations belong to the same group.
2. LDA, two classes
Now suppose . Let be the index set for class , , and .
Projecting onto maps each to a scalar , and each class mean to .
First attempt: maximize the squared distance between projected means,
This fails in two ways. Without a norm constraint the objective is unbounded. With it still ignores within-class scatter: a direction that pulls means far apart but leaves both classes smeared across the axis is useless for discrimination.
Fisher’s correction: normalize the between-class separation by the total within-class scatter. Define the within-class scatter matrices:
and the between-class scatter matrix:
Note that — the squared separation of projected means — and is the total projected within-class variance. Fisher’s criterion is the ratio of these:
A direction with large separates the class means by much more than the within-class spread along the same direction.
3. Fisher’s linear discriminant
To find the that maximizes , differentiate with respect to and set to zero. Writing and :
Rearranging:
This is the generalized eigenvalue problem , where at the optimum.
For two classes, has rank one, so is always proportional to . The generalized eigenvalue problem reduces to:
The scalar does not affect the direction of , so:
In two dimensions, if , the inverse is:
Comparison with PCA. The PCA direction is the top eigenvector of the full scatter matrix . It maximizes total variance irrespective of class structure. The LDA direction instead corrects for within-class geometry: if (both classes spherically symmetric with equal spread), then — the direction straight from one mean to the other. If , the inverse covariance stretches and rotates that difference to account for correlated or unequally scaled features.
4. Seeing LDA work — and fail
Use the widget below. Add a cluster of class 1 points with CLASS 1 active, then switch to CLASS 2 and add points in a clearly separated region. The solid line shows — the LDA axis. The dashed line shows the PCA direction of the combined cloud. The marks are the class means.
With well-separated, roughly symmetric clusters, LDA finds a sensible discriminant and the two lines diverge as expected: PCA tracks total spread, LDA tracks inter-class separation.
Now try to break it. Give class 1 a tight cluster in the upper left. Give class 2 two sub-clusters — one in the lower left, one in the upper right, so that they form an “X” pattern with class 1 in the middle. The class 2 mean falls somewhere between those sub-clusters, possibly right on top of the class 1 cluster. Watch the LDA axis try to separate that ghost mean from class 1. It cannot: there is no single linear projection that distinguishes the two groups when the positive class is bimodal.
This is not a contrived failure. It is a faithful model of what happens when the positive class contains clinically distinct subgroups.
5. Assumptions and where LDA fails in practice
The Gaussian-likelihood assumption
LDA’s theoretical underpinning is that each class is drawn from a multivariate normal distribution with a shared covariance matrix. Under that model, the Bayes-optimal decision rule is a linear function of , and LDA recovers it. Violate the model assumptions and the guarantee collapses.
Real-world feature sets routinely contain:
- Binary indicators — features that take only values 0 and 1, for which no Gaussian model is appropriate;
- Sparse counts — features whose distribution is concentrated at zero with a long right tail;
- Zero-inflated data — a mix of structural zeros and a positive process, producing bimodal marginals;
- Skew and outliers — heavy-tailed distributions where the mean is not a reliable center;
- Nonlinear relationships — interactions between features that a linear projection cannot capture.
Non-normality alone rarely kills LDA outright; the method is often robust to moderate departures. The deeper problem is structural.
The component ceiling
For classes, the between-class scatter matrix has rank at most . For two-class problems, LDA produces exactly one discriminant component:
A single scalar summarizes the entire observation. This is by design — one dimension is all the supervision can support with two classes. The question is whether one dimension is enough to express the discriminative structure.
Phenotype heterogeneity: the structural failure
Consider a binary patient-identification problem. The positive class contains two clinically distinct groups:
- Group A: high cardiac involvement, low respiratory involvement.
- Group B: low cardiac involvement, high respiratory involvement.
These groups arrive at the positive label by different routes. Their mean — moderate cardiac, moderate respiratory — describes neither of them accurately. LDA computes , where is this uninformative average. The discriminant axis is anchored to a point that no positive patient actually resembles.
In a feature space of claims codes, Group A might have high ICD codes for heart failure and low codes for COPD; Group B, the reverse. A linear projection that moves toward “high cardiac, low respiratory” scores Group A well and Group B poorly, or vice versa. There is no single direction in feature space that scores both groups above the negative class — unless the negative class happens to be located centrally in a way that makes it work by accident.
PCA, being unsupervised, is not immune to this problem. But it is also not subject to it in the same way. If the first PC aligns with cardiac involvement, it separates Group A from negatives along that axis. A subsequent PC may recover Group B. Without the constraint of a single supervised direction, PCA can represent the heterogeneity in its top components and leave classification to a downstream model trained on those components.
Coefficient interpretation caveats
Even when LDA works correctly, the components of carry interpretation traps:
Correlated features. If two features and are highly correlated (both measuring similar clinical activity), their individual coefficients may be small, opposite in sign, or unstable across samples — even though together they are discriminative. The coefficient on reflects its marginal contribution conditional on being in the model, not its standalone importance.
Scaling sensitivity. LDA operates on raw feature values. A feature measured in thousands (e.g., total claims dollars) will have a smaller coefficient than one measured in units (e.g., a count), even if their discriminative power is comparable. Coefficient magnitude should not be compared across features unless they have been standardized.
Conditional, not causal, contribution. The sign and magnitude of a coefficient reflect how the feature moves an observation along the discriminant axis — a statistical association given the training data. It does not identify causal drivers of class membership.
One axis, many routes. For any components, LDA imposes a fixed low-dimensional summary. When the positive class contains several phenotypic subtypes with distinct feature profiles, that summary cannot represent all of them. The coefficient on a feature that is elevated only in Group A will be attenuated by the Group B observations for which it is not elevated. Both the direction and the coefficients become descriptions of neither subgroup.
These are not reasons to avoid LDA. They are reasons to inspect the within-class structure before committing to a single supervised projection, and to treat coefficient magnitudes as statistical summaries rather than scientific findings.