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

Quadratic Discriminant Analysis (QDA)

Quadratic discriminant analysis is LDA without the shared-covariance assumption: each class gets its own Gaussian mean and covariance, so the log-determinant and quadratic terms no longer cancel and the decision boundaries become conic sections (ellipses, parabolas, hyperbolas). It can separate classes that differ only in spread, but it estimates K times as many covariance parameters and overfits with little data. Regularised discriminant analysis blends QDA with LDA. This page covers the quadratic discriminant, the parameter count and bias–variance trade-off, the boundary geometry, regularisation, and when to choose QDA, LDA or naive Bayes. In the exercises you implement QDA and RDA and show QDA separating classes with equal means; then you classify rocks versus shadows for a rover and compare LDA, QDA and cross-validated RDA as the training set grows.

Level 0: Foundation

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

When classes differ in shape, not just position

Shadows in a rover’s camera are uniformly dark: their texture features hardly vary. Rocks vary a lot. On average the two might look similar, so a straight line between their centres cannot tell them apart. But their spreads differ. QDA gives each class its own elliptical cloud. The boundary becomes curved, wrapping around the tight class, and points far out in any direction go to the spread-out class.

QDA: each class gets its own ellipse, so the boundary curves
training error: QDA 22.5% · LDA 22.5% · means and covariance parameters: QDA 10, LDA 7
Shaded regions: QDA's decision (orange where the orange class is more likely). The orange class wins far out in its long directions, because its spread is larger there, so the boundary wraps around the blue class. Make both spreads about 0.8 (like blue) and the curve straightens toward LDA's line. With only 6 points per class, QDA's curve changes drastically when the sample changes (move the points slider by one step): it estimates more parameters from the same data.
Why engineers care

Many sensor classes differ in variability: nominal versus faulty vibration (faults are noisier), clear versus cloudy pixels, quiet versus active periods. QDA captures this with a closed-form, probabilistic model. Its cost in data must be respected, and regularised versions make it practical.

📝 Quick check (Level 0)
0/3 answered
  1. 1. QDA differs from LDA by giving each class…
  2. 2. QDA boundaries are…
  3. 3. Can QDA separate two classes with the same mean?

Level 1: Beginner

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

Same mean, different spread

Class A is N(0, 1) and class B is N(0, 2²), with equal priors.

  • LDA sees identical means, so it has no boundary to draw: it is stuck at chance.
  • QDA compares −log σ − x²/(2σ²) for the two classes. Class B wins when x² > 2σ_A²σ_B² ln(σ_B/σ_A)/(σ_B² − σ_A²) = 8 ln 2/3 = 1.848, that is, when |x| > 1.36.
  • The rule is “tight values near 0 → A, extreme values → B”. No single threshold could express that.

Counting parameters. With p = 10 features and K = 3 classes:

  • LDA estimates 3·10 means + 55 shared covariance entries (+ 2 priors) = 87 parameters;
  • QDA estimates 3·10 + 3·55 + 2 = 197.

With 20 examples per class, each class covariance (55 numbers) would be estimated from 20 points, which is hopeless without regularisation.

The steps in plain English:

  1. For each class, estimate its mean, its own covariance and its prior.
  2. For a new point, score each class: −½ log|Σₖ| − ½ (Mahalanobis distance to μₖ)² + log πₖ.
  3. Predict the highest score. The softmax of the scores gives the probabilities.
  4. With few data per class, shrink each Σₖ toward the pooled covariance (RDA) or toward a diagonal or identity.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Parameters in one 10 × 10 covariance?
  2. 2. For A = N(0, 1), B = N(0, 4), equal priors, x = 3 goes to…
  3. 3. The −½ log|Σₖ| term penalises…

Level 2: Intermediate

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

The discriminant

Model: x | y = k ~ N(μₖ, Σₖ), with P(y = k) = πₖ.

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

Boundaries. δ_j(x) = δ_k(x) is a quadratic equation in x: a conic section in 2-D and a quadric surface in higher dimensions. The difference Σ_j⁻¹ − Σₖ⁻¹ decides whether it is an ellipse, a parabola or a hyperbola.

Estimation:

  • means and priors as in LDA;
  • Σ̂ₖ = sample covariance of class k (divided by nₖ − 1);
  • each Σ̂ₖ must be invertible, so nₖ > p is needed (and ≫ p for stability).

Regularised discriminant analysis (Friedman, 1989): Σₖ(α) = αΣ̂ₖ + (1 − α)Σ̂_pooled, optionally followed by shrinkage toward a scaled identity. Here α = 1 is QDA and α = 0 is LDA. Choose α by cross-validation.

from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis
qda = QuadraticDiscriminantAnalysis(reg_param=0.1).fit(X, y)   # reg_param shrinks each Σₖ toward the identity
qda.predict_proba(X_new)

Use it when classes differ in covariance and you have plenty of data per class relative to p², or you can regularise. Prefer LDA (or naive Bayes) with few data or many features. Prefer trees, kernels or neural networks when the classes are not even roughly Gaussian.

🐍 Exercise 1: QDA and regularised discriminant analysis
Implement QDA with optional blending toward the pooled covariance (RDA), its quadratic discriminants and predictions, and the parameter count of QDA versus LDA; show that with equal means and different covariances QDA separates the classes while LDA is at chance, and check the estimated covariance and the shape of the boundary.
📝 Quick check (Level 2)
0/3 answered
  1. 1. RDA with α = 0 equals…
  2. 2. QDA needs, per class, at least…
  3. 3. scikit-learn's reg_param in QDA shrinks Σₖ toward…

Level 3: Advanced

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

Bias, variance and the family tree

The family of Gaussian classifiers, from fewest to most covariance parameters:

  • nearest-mean (Σ = I);
  • naive Bayes (diagonal Σₖ, D3.31);
  • LDA (shared full Σ);
  • QDA (full Σₖ).

Moving right lowers bias (more flexible boundaries) and raises variance (more parameters: Kp(p + 1)/2 for QDA). RDA, and diagonal/shared blends, fill in the gaps.

Data requirements. The QDA discriminant’s estimation error grows roughly with Kp²/n. A rule of thumb is nₖ ≳ 5p–10p per class for an unregularised QDA. In exercise 2 (p = 8), QDA was worse than LDA at 12 per class even when the true covariances differed, and won clearly at 150 per class.

Equivalence with logistic regression on quadratic features. QDA’s log-odds are quadratic in x, so logistic regression on [x, x², xᵢxⱼ] has the same boundary family. QDA fits it generatively, which is more efficient under Gaussianity and less robust otherwise, the same trade-off as LDA versus logistic regression.

Interview questions.

  • When would QDA beat LDA? When class covariances clearly differ (in spread or orientation) and there is enough data per class.
  • Why might QDA be overconfident? With few points, the estimated Σₖ are too small along poorly sampled directions, so Mahalanobis distances blow up and posteriors become extreme. Regularisation fixes this.
📝 Quick check (Level 3)
0/3 answered
  1. 1. Order by flexibility (least to most):
  2. 2. QDA's log-odds are…
  3. 3. Logistic regression with the same boundary family as QDA uses…

Level 4: Expert

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

Rocks or shadows?

History.

  • Smith (1947) studied quadratic discrimination for unequal covariances.
  • QDA became part of the classical “normal-based” discriminant toolkit alongside Fisher’s LDA.
  • Friedman’s regularised discriminant analysis (1989) made it usable with small samples by bridging QDA and LDA.
  • In remote sensing, Gaussian maximum-likelihood classification of multispectral pixels is exactly QDA.

Exercise 1. Equal means, with covariances diag(1, 1) and diag(9, 0.09). QDA reaches accuracy 0.809, while LDA is at chance (0.498). The estimated class-1 covariance is close to diag(9, 0.09). For p = 10 and K = 3, QDA estimates 197 parameters against LDA’s 87.

Exercise 2: rocks versus shadows. Setup: 8 texture features, 25 repetitions per size. The table shows test error; RDA’s α is chosen by 5-fold CV from 0, 0.25, 0.5, 0.75 and 1.

Scenario, patches per class LDA QDA RDA (CV α)
Equal shapes, 12 0.101 0.222 0.104
Equal shapes, 30 0.065 0.095 0.067
Equal shapes, 150 0.051 0.054 0.052
Different shapes, 12 0.158 0.171 0.150
Different shapes, 30 0.099 0.060 0.061
Different shapes, 150 0.078 0.030 0.032
  • When LDA’s assumption holds, QDA’s extra parameters only hurt: its error is more than double at 12 patches per class.
  • When the shapes differ and data are plentiful, QDA cuts the error by more than half compared with LDA.
  • With only 12 patches per class, QDA loses even when it is the right model. Its 2 × 36 covariance entries are too noisy.
  • Cross-validated RDA is within 0.006 of the better of the two in every case: choosing α by CV automates the bias–variance choice.
🐍 Exercise 2 (research): LDA, QDA and RDA for rock/shadow classification
Simulate 8-feature rock and shadow patches with equal or different class covariances; compare LDA, QDA and regularised discriminant analysis (α by 5-fold CV) by test error for 12, 30 and 150 training patches per class.

QDA in AI, robotics and aerospace

  • Remote sensing: Gaussian maximum-likelihood classification of multispectral pixels.
  • Terrain and hazard perception: classes with different texture variability.
  • Fault detection: faulty regimes are often noisier than nominal ones, giving different covariances.
  • Speech and gesture: Gaussian class models (and GMM-HMMs, D3.36) extend QDA to sequences.

References

  1. C. A. B. Smith (1947). “Some examples of discrimination.” Annals of Eugenics 13(1).
  2. J. H. Friedman (1989). “Regularized discriminant analysis.” JASA 84(405).
  3. T. Hastie, R. Tibshirani, J. Friedman (2009). The Elements of Statistical Learning, 2nd ed., section 4.3. Springer.
  4. G. J. McLachlan (2004). Discriminant Analysis and Statistical Pattern Recognition. Wiley.
  5. J. A. Richards (2013). Remote Sensing Digital Image Analysis, 5th ed., chapter 8. Springer.