Linear Discriminant Analysis (LDA)

Machine Learning
Introduced by
Fisher, R. A.
Year
1936
Type
Supervised dimensionality reduction and linear classifier

What does it do?

Linear Discriminant Analysis (LDA) is a supervised method, introduced by Ronald A. Fisher in 1936, that finds linear combinations of features which best separate predefined classes.

It serves both as a supervised dimensionality-reduction technique and as a linear classifier, the latter under Gaussian class-conditional distributions with a shared covariance matrix.

The intuition behind the method

Imagine projecting a cloud of multi-dimensional data points onto a single line. Most lines would mix the classes together. LDA finds the one line — or the few directions — along which the class clusters are pushed as far apart as possible relative to their own internal spread. Once the data are projected onto this lower-dimensional space, class membership becomes easy to read off: each new observation is assigned to whichever class center it lands closest to. The key insight Fisher contributed is that separability should be measured not in raw distance but as a ratio of between-class spread to within-class spread, a criterion that has an exact closed-form solution.

History

Ronald A. Fisher introduced the linear discriminant in his 1936 paper 'The use of multiple measurements in taxonomic problems', using sepal and petal measurements to separate Iris flower species. He defined the criterion as a ratio of between-group to within-group variance; the matrix notation used on this page (S_W and S_B) is the multivariate form of that ratio. The probabilistic interpretation, in which LDA is a generative model with Gaussian class-conditional distributions and a shared covariance, is the form used for the discriminant score in Hastie, Tibshirani, and Friedman's The Elements of Statistical Learning (Chapter 4). The derivation of the classifier from Bayes' theorem, its extension to several predictors, and the contrast with quadratic discriminant analysis are also treated in An Introduction to Statistical Learning (2013, Section 4.4). LDA remains a standard reference method in statistics and machine learning.

When to use it

LDA is appropriate when the goal is multiclass classification or supervised dimensionality reduction and the data plausibly satisfy its two core assumptions: (1) each class follows a multivariate Gaussian distribution and (2) all classes share the same covariance matrix. It performs well when the number of observations is moderate to large relative to the number of features, and it is especially useful as a preprocessing step before other classifiers when interpretable low-dimensional projections are needed. It is not appropriate when class boundaries are nonlinear, when features are clearly non-Gaussian (e.g., counts or binary indicators without transformation), when classes have very different covariance structures (use QDA instead), or when p is close to or exceeds n (use regularized LDA or PCA first).

Limitations and considerations

  • Assumes multivariate Gaussian class-conditional distributions, which many real datasets violate.
  • The equal-covariance assumption is often unrealistic; severe violations inflate error rates.
  • Sensitive to outliers because sample means and covariances are not robust estimators.
  • Breaks down when p is close to or larger than n because S_W becomes singular or ill-conditioned.
  • Linear decision boundaries cannot capture curved or complex class separations.
  • Prior class probabilities must be specified or estimated from possibly unrepresentative training data.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Closed-form solution: the discriminant directions follow from an eigendecomposition, so no iterative optimization or hyperparameter search is required.
  • Simultaneous dimensionality reduction and classification within a single framework, with projections that can be inspected directly.
  • The discriminant axes are explicit linear combinations of the original features, so the contribution of each variable to the separation can be read from the weights.
  • Handles multiclass problems naturally, yielding at most K-1 discriminant axes for K classes.
  • Under the Gaussian, shared-covariance model it provides class posterior probabilities; these are model-based and are not guaranteed to be well calibrated when those assumptions fail.

Applications

  • Face recognition and biometric identification, where LDA projects high-dimensional pixel vectors onto a low-dimensional discriminative space (Fisherfaces).
  • Medical diagnosis and biomarker discovery, classifying patients into predefined disease groups based on clinical measurements.
  • Chemometrics and spectroscopy, reducing high-dimensional spectral data to a few interpretable discriminant axes.
  • Natural language processing feature engineering, extracting class-discriminative features before downstream classifiers.
  • Visualizing labeled data, where the first one or two discriminant axes show how well the predefined classes separate in a low-dimensional plot.

How it works

How it works

1

The within-class scatter matrix S_W captures how spread out the observations are around their own class mean. A small S_W means each class is tightly clustered. It is computed by summing the outer products of mean-centered observations across all classes, and its inverse will later normalize the between-class distances so that tight, well-separated clusters score higher than loose ones.

Formula
S_W = \sum_{k=1}^{K} \sum_{i \in C_k} (\mathbf{x}_i - \boldsymbol{\mu}_k)(\mathbf{x}_i - \boldsymbol{\mu}_k)^\top
2

The between-class scatter matrix S_B captures how far apart the class means are from the overall mean of the data, weighted by each class's size. A large S_B means the class centroids are spread widely across the feature space. Together, S_W and S_B encode exactly the trade-off that LDA optimizes: maximize spread between classes relative to spread within classes.

Formula
S_B = \sum_{k=1}^{K} n_k (\boldsymbol{\mu}_k - \boldsymbol{\mu})(\boldsymbol{\mu}_k - \boldsymbol{\mu})^\top
3

Fisher's criterion asks for the projection direction w that maximizes the ratio of between-class variance to within-class variance in the projected space. This is equivalent to finding directions along which classes are well separated relative to their own internal dispersion. Because the criterion is a generalized Rayleigh quotient, it has an analytic solution without requiring iterative optimization.

Formula
\mathbf{w}^* = \arg\max_{\mathbf{w}} \frac{\mathbf{w}^\top S_B \mathbf{w}}{\mathbf{w}^\top S_W \mathbf{w}}
4

The optimal projection directions are the eigenvectors of the matrix S_W^{-1} S_B, ordered by their eigenvalues. The number of meaningful directions is at most K-1, where K is the number of classes, because S_B has rank at most K-1. For binary classification a single discriminant direction is sufficient; for K classes one extracts up to K-1 discriminant axes to form the reduced-dimensional projection space.

Formula
S_W^{-1} S_B \mathbf{w} = \lambda \mathbf{w}
5

Once the model is fit under the assumption of Gaussian class-conditional distributions with a shared covariance matrix, each new observation is classified by computing a linear discriminant score for every class and assigning the label with the highest score. The score depends on the log prior probability π_k of the class, the class mean μ_k, and the shared inverse covariance Σ^{-1}, where Σ is the pooled within-class covariance estimate, a scaled version of the within-class scatter S_W described above. Because the covariance is shared, the decision boundaries between classes are linear hyperplanes.

Formula
\hat{y} = \arg\max_{k} \left[ \log \pi_k - \tfrac{1}{2} \boldsymbol{\mu}_k^\top \Sigma^{-1} \boldsymbol{\mu}_k + \mathbf{x}^\top \Sigma^{-1} \boldsymbol{\mu}_k \right]

Common pitfalls

  • Applying LDA to highly non-Gaussian features (counts, skewed distributions, binary variables) without checking assumptions first.
  • Ignoring the equal-covariance assumption when classes clearly differ in spread; comparing per-class spread visually (for example, per-class scatter plots or variances) helps reveal this.
  • Using LDA when p approaches n without regularization, as S_W will be near-singular and the solution unstable.
  • Treating the discriminant scores as raw distances without accounting for class priors when class frequencies are unequal.
  • Confusing LDA with Latent Dirichlet Allocation, a completely different probabilistic topic model that shares the same acronym.

Frequently asked questions

What is the difference between LDA and PCA?

PCA is unsupervised and finds the directions of maximum total variance regardless of class labels. LDA is supervised and finds the directions that maximize class separation relative to within-class spread. PCA preserves the most variance in the data; LDA preserves the most class-discriminatory information. For classification tasks, LDA projections are often more discriminative than PCA projections, although this is not guaranteed.

When should I use QDA instead of LDA?

Quadratic Discriminant Analysis (QDA) relaxes the equal-covariance assumption and fits a separate covariance matrix per class, producing curved (quadratic) decision boundaries. Use QDA when classes clearly differ in their spread or shape and you have enough observations per class to estimate each covariance matrix reliably. LDA is preferred when the equal-covariance assumption is reasonable or when sample sizes are small and the extra parameters of QDA would lead to overfitting.

How many discriminant dimensions should I retain?

At most K-1 discriminant axes carry class-discriminatory information for K classes, so for binary classification there is exactly one discriminant axis. Beyond that bound, there is no fixed rule. Inspect the eigenvalues in descending order and the separation each axis provides, and retain the axes that contribute meaningfully. For visualization, the first one or two axes are often used.

What should I do if p is large relative to n?

When the number of features p is close to or exceeds the number of observations n, the within-class scatter matrix S_W becomes singular or ill-conditioned and cannot be reliably inverted. Standard remedies are: (1) apply PCA first to reduce dimensionality, then run LDA on the principal components; (2) use regularized discriminant analysis, which shrinks the covariance estimate toward a simpler structure such as a scaled identity matrix; or (3) use a penalized variant such as sparse LDA.

Related methods

Sources

  1. Fisher, R. A. (1936). The use of multiple measurements in taxonomic problems. Annals of Eugenics, 7(2), 179–188.

    Open DOI reference
  2. Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning: Data Mining, Inference, and Prediction (2nd ed., Ch. 4). Springer.

    ISBN: 978-0-387-84857-0
  3. An Introduction to Statistical Learning (2013), Section 4.4, p. 138–149