Skip to content
AI.info

Classical machine learning

Linear and Quadratic Discriminant Analysis

Learn LDA and QDA as generative classifiers, compare covariance assumptions, and use shrinkage, priors, and projection carefully.

By the end you can

Discriminant analysis models how each class could have generated the features

Linear and quadratic discriminant analysis are generative classifiers. They estimate class priors and class-conditional feature distributions, then apply Bayes' rule.

Their decision boundaries emerge from distributional assumptions rather than from a boundary fitted directly. That gives them a different failure profile from logistic regression, which models the conditional class probability directly. What follows is mostly published arithmetic: what the generative assumption buys when it holds, and what it costs when it does not.

Case

Fisher's 1936 paper arrived with the iris table that statistics packages still ship

The founding example is ninety years old and still ships with every statistics package. It is a table of 150 iris flowers: three species, fifty of each, four measurements per flower. Edgar Anderson took the measurements. R. A. Fisher used them in 1936 to introduce the linear discriminant function.

Fisher did not only propose the method. He printed the arithmetic. Solving his equations on the fifty setosa and fifty versicolor plants gave the multipliers λ1 = −0.0311511, λ2 = −0.1839075, λ3 = +0.2221044 and λ4 = +0.3147370 — that is, the compound x1 + 5.9037·x2 − 7.1299·x3 − 10.1036·x4. That compound averages 12.3345 cm in setosa and −21.4815 cm in versicolor. The gap is 33.816 cm. The within-species standard deviation for single plants is 3.3804 cm (variance 11.4269 = 1085.5522/95). Two species, almost exactly ten standard deviations apart on a single number. That is what a discriminant function is, and it is why the method was believable on the day it was published.

The third species is the reason the table is still taught. Virginica arrives later in the paper, on a separate three-species compound (coefficients, ×100: sepal length −3.308998, sepal breadth −2.759132, petal length +8.866048, petal breadth +9.392551). On that compound setosa and versicolor differ by 33.69 units, “so great compared with the standard deviations that no appreciable overlapping of values can occur”. Virginica and versicolor differ by only 15.31 units, “less than four times the standard deviation of each species”. Their histograms overlap in Fisher's Fig. 1, “so that a certain diagnosis of these two species could not be based solely on these four measurements of a single flower taken on a plant growing wild”. The founding example already contains one easy class and one hard pair. The UCI Machine Learning Repository has distributed the same table since 30 June 1988 and records the identical geometry — “One class is linearly separable from the other 2; the latter are not linearly separable from each other.”

What the packages ship is not byte-identical to what Fisher printed. In 1998 five researchers compared the electronic file with the paper, and published what they found: “Out of curiosity, on September 7, 1998 we fetched Iris from the anonymous FTP site “ftp.ics.uci.edu” under the directory “pub/machine-learning-databases” and discovered not one, but two errors in it!” Vector 35 is (4.9, 3.1, 1.5, 0.2) in Fisher but was (4.9, 3.1, 1.5, 0.1) in the file. Vector 38 is (4.9, 3.6, 1.4, 0.1) in Fisher but was (4.9, 3.1, 1.5, 0.1). The UCI record still carries the correction. The most examined table in the discipline needed an erratum, twenty-seven years after it was first typed into a computer.

Comparison

Shared or class-specific covariance changes the boundary

The covariance assumption controls flexibility and sample demand.

The third column is not a hand-wave. “Shrinks covariance estimates toward simpler structure” names a specific published estimator with a closed form. Ledoit and Wolf published it in 2004. It “is the asymptotically optimal convex linear combination of the sample covariance matrix with the identity matrix”: distribution-free, and optimal under quadratic loss as p and n go to infinity together. It is needed because for p larger than n the sample covariance matrix is not even invertible.

scikit-learn ships that lemma as one flag. Its 1.9.0 user guide, under “Shrinkage and Covariance Estimator”, says of shrinkage='auto': “This automatically determines the optimal shrinkage parameter in an analytic way following the lemma introduced by Ledoit and Wolf.” The parameter runs from 0, the empirical covariance, to 1, the diagonal matrix of variances. Regularized discriminant analysis is a dial between the two columns to its left, and the position of that dial can be computed rather than guessed.

FigureComparison · 3 columns

LDA

Assumes classes share one covariance matrix.

  • Linear decision boundaries
  • Fewer covariance parameters
  • Often stable with moderate samples
  • Can support dimensional projection

QDA

Estimates a covariance matrix for each class.

  • Quadratic decision boundaries
  • Captures class-specific spread and orientation
  • Needs more observations per class
  • Can become unstable in high dimensions

Regularized discriminant analysis

Shrinks covariance estimates toward simpler structure.

  • Useful when dimensions are large
  • Trades flexibility for stability
  • Requires tuning
  • Does not fix invalid Gaussian assumptions

Visual

How covariance shapes class evidence

Means locate class centers. Covariance describes scale, correlation, and orientation around those centers. Every quantity in the chain below is estimated from data, and each one has its own sample cost.

FigureHierarchy · 5 levels
  • Class prior

    Base prevalence before observing the features.

    • Class mean

      The center of the modeled feature distribution for one class.

      • Covariance

        The spread and correlation pattern around the class mean.

        • Discriminant score

          The combined log evidence used to compare classes.

          • Posterior probability

            A normalized model probability requiring empirical calibration checks.

Example

When the assumptions are useful and when they strain

Discriminant analysis can be strong on small structured datasets, but the feature geometry matters.

  • Chemical spectra: LDA can work well after dimension reduction when class clouds have similar covariance structure.
  • Handwritten measurements: QDA may capture classes with different variability if enough examples support each covariance estimate.
  • Wide biomarker panels: unregularized QDA can be singular, because covariance estimation requires many observations and for p larger than n even the sample covariance matrix is not invertible.
  • Skewed financial variables: transformations may be needed, because heavy tails and outliers distort Gaussian estimates.
  • Changing prevalence: prior probabilities should reflect the deployment population rather than an oversampled training set.

LDA can also define a supervised projection

For multiple classes, LDA finds directions that emphasize separation between class means relative to variation within classes. The number of those directions is capped at classes minus one. scikit-learn documents the limit for its own implementation — “This shows that, implicit in the LDA classifier, there is a dimensionality reduction by linear projection onto a K−1 dimensional space.”

This supervised use differs from PCA, which ignores labels and preserves directions of overall variance rather than class separation. Whether supervision then wins is an empirical question. Face recognition is where it was raced both ways.

The first race went to supervision. A 1997 leave-one-out test on the 160-image, 16-person Yale face database put three methods side by side. Fisherfaces gave error rates of 7.3% on the close crop and 0.6% on the full face, in a 15-dimensional reduced space. Eigenfaces gave 24.4% and 19.4% in 30 dimensions. Correlation gave 23.9% and 20.0% in 160. On the full face that is 0.6% against 19.4%.

Then Martinez and Kak ran the opposite experiment, in 2001: 50 subjects from the AR face database, only two training and five test images per person, repeated over all 21 train/test splits. PCA recognition saturated at 44–75% for f=80. LDA swung from 31% to 68% at f=10, and from 41% to 82% at f=40 — higher at its best, worse at its worst, and far more dependent on which split it happened to get. “Our overall conclusion is that when the training data set is small, PCA can outperform LDA and, also, that PCA is less sensitive to different training data sets,” they wrote in their abstract.

Supervision is the difference. Two images per class is where the difference stops paying.

Steps

Assess discriminant analysis before trusting its probabilities

The model is compact, so assumption checks can be concrete. Step 4 is not a vague instruction. In scikit-learn's LinearDiscriminantAnalysis the shrinkage parameter runs from 0, the empirical covariance, to 1, the diagonal matrix of variances, and shrinkage='auto' places it by the Ledoit–Wolf lemma instead of by taste.

FigureProcess · 6 steps
  1. 1. Inspect class counts

    Confirm enough observations exist for the covariance complexity.

  2. 2. Transform cautiously

    Address extreme skew and scale while fitting transforms inside folds.

  3. 3. Compare covariance structure

    Check whether class spreads appear similar or distinct.

  4. 4. Tune shrinkage if needed

    Regularize high-dimensional or noisy covariance estimates.

  5. 5. Validate priors and calibration

    Separate training sampling from deployment prevalence.

  6. 6. Compare conditional baselines

    Test logistic regression and simpler models on the same split.

Analogy

Classifying points by competing weather maps

Every class supplies a weather map. The map describes where observations tend to cluster and how uncertainty stretches across directions. A new point is assigned using the map that gives it the strongest posterior evidence.

The map misleads where real feature distributions are multimodal, discrete, or heavy-tailed. One Gaussian cloud per class can then be a poor map. Fisher's setosa cloud is a good map. His versicolor and virginica clouds sit fifteen units apart on a compound whose species standard deviation is a quarter of that. They are the same map drawn twice.

Discriminant analysis is powerful when class geometry is compact enough to model explicitly.

Key idea

A quadratic boundary is not automatically a better boundary

QDA can fit class-specific covariance and therefore bends the decision surface. The same freedom multiplies estimated parameters and can make performance fragile when samples are limited.

Choose QDA because held-out evidence supports distinct covariance structure, not because curvature sounds more realistic. Curvature is not evidence.

Gene-expression data put that trade to the test, and the most restricted classifier won. Dudoit and two colleagues compared nearest neighbours, discriminant analysis, and single and aggregated classification trees across three tumour datasets: Golub's leukaemia data, Alizadeh's lymphoma data and the NCI 60 cancer cell lines. Their UC Berkeley statistics technical report is dated June 2000; it was published in the Journal of the American Statistical Association in March 2002. The conclusion was that “simple classifiers such as DLDA and nearest neighbors perform remarkably well compared to more sophisticated methods such as aggregated classification trees”. DLDA is the most restricted member of the family. It uses a diagonal covariance matrix, and ignores correlations between genes outright. Fisher's LDA, which estimates the full shared covariance, had the highest error rates. The report names the cause — “the poor estimation of covariance matrices with a small training set and a fairly large number of genes p”. Cutting the number of variables improved it: “decreasing the number of variables resulted in an improved performance of FLDA”.

Four years later the empirical finding acquired a proof. Bickel and Levina open the abstract of their 2004 paper with the result itself: “We show that the ‘naive Bayes’ classifier which assumes independent covariates greatly outperforms the Fisher linear discriminant rule under broad conditions when the number of variables grows faster than the number of observations, in the classical problem of discriminating between two normal populations.” Their Theorem 1(a) is the sharp form. If p/n → ∞ the worst-case error of Fisher's rule tends to 1/2, “so the worst case of the rule is no better than random guessing”. Theorem 1(b) gives the other half: if (log p)/n → 0 the independence rule converges instead to Φ̄(√K₀·c/(1+K₀)), strictly better than a coin toss. That holds so long as K₀, the worst condition number of the correlation matrix, stays bounded. Bickel and Levina add the caveat. If K₀ → ∞ the independence rule too is no better than random guessing. Fan and Fan took this as the starting point of their own work and showed the same collapse can hit almost all linear discriminants once every feature is used.

The warning is therefore stronger than a caution about QDA. Estimating a full covariance matrix in a wide dataset is not merely inefficient. It has a proved limit at the accuracy of a coin toss.

Flexibility without enough class-specific data becomes covariance noise.

Generative assumptions can help in small samples and hurt under misspecification

When the Gaussian and covariance assumptions are approximately useful, LDA can estimate an efficient boundary from relatively few parameters. Logistic regression may be the more robust choice when the class-conditional distributions are badly misspecified.

The first half of that has a price tag on it. In 1975 Bradley Efron tabulated the asymptotic relative efficiency of logistic regression against normal discrimination, with equal class priors. Δ is the square root of the Mahalanobis distance. The efficiency runs 1.000 at Δ=0, 1.000 at Δ=0.5, .995 at Δ=1, .968 at Δ=1.5, .899 at Δ=2, .786 at Δ=2.5, .641 at Δ=3, .486 at Δ=3.5 and .343 at Δ=4. Note where the curve falls. It is flat while the classes overlap heavily, and it collapses as they separate — “Just when good discrimination becomes possible, for Δ between 2.5 and 3.5, the ARE of the logistic procedure falls off sharply”. His abstract states the summary: “Typically, logistic regression is shown to be between one half and two thirds as effective as normal discrimination for statistically interesting values of the parameters.”

Sixteen years later Ruiz-Velasco recomputed the same efficiency independently, in Biometrika in 1991, and found that it does not depend on how many variables there are: “The Pitman asymptotic efficiency for hypothesis tests in this context is the same as the asymptotic relative efficiency calculated using mis-classification rates and is independent of the number of explanatory variables and the number of parameters to be tested.”

So the price of dropping the generative assumption is roughly a third to a half of your sample, in exactly the regime where the classes are worth telling apart — provided the assumption is true. The comparison remains empirical: use consistent preprocessing, priors, splits, and decision metrics.

There is a way to keep the generative model and still survive a wide dataset. Shrink the class centres until most of the features drop out. Tibshirani and three colleagues did that in PNAS in 2002, with a method that is “an enhancement of the simple nearest prototype (centroid) classifier”. There is one centroid per class. Each is shrunk toward the overall centroid until most genes contribute nothing. On the small round blue cell tumour data “only 43 genes … are the only ones required for the classification. This approach yields zero test and zero training errors.” On the leukaemia data they passed over the cross-validation minimum, which “leaves about 1,000 genes”. They took instead the point where the error begins to climb: 21 genes, a cross-validation error of 1/38 and a test error of 2/34. Modelling the feature distribution paid here. It paid because the model of it was kept small enough to estimate.

Model the feature distribution only when that structure earns predictive or explanatory value.

Key takeaways