Method · Statistics Library

Quadratic discriminant analysis (QDA)

Quadratic discriminant analysis classifies observations into known classes like LDA but gives each class its own covariance matrix, allowing curved (quadratic) decision boundaries at the cost of more parameters to estimate per class.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

QDA is LDA's more flexible sibling. Both model each class as a cluster of points shaped like a multivariate bell curve, but LDA insists every class share the exact same spread and orientation, while QDA lets EACH class have its own spread, scale, and orientation entirely. That extra freedom means QDA's decision boundaries between classes can curve (ellipses, parabolas, hyperbolas) rather than being forced into straight lines the way LDA's boundaries are.

This flexibility is not free. Because each class now gets its own full covariance structure estimated from only ITS OWN rows, QDA needs many more numbers estimated overall than LDA does, and every one of those numbers is estimated from a smaller slice of the data (just one class) than LDA's single shared estimate would use. If any class is small relative to the number of predictors, its own covariance estimate becomes noisy or even mathematically unusable, and QDA can overfit badly or fail outright.

A useful rule of thumb for deciding between the two: if you have reason to believe the classes differ mainly in WHERE they're centered (their means) rather than in how spread out or oriented they are, LDA is usually the safer, more stable choice; QDA earns its extra complexity specifically when classes genuinely differ in their spread or shape, not just their location.

Unlike linear discriminant analysis, QDA gives each class its own class-specific covariance, meaning its own spread and tilt, which lets the boundary between classes curve. Covariance regularization shrinks each class's estimated spread toward a simpler shape, which helps when a class has few rows.

Practitioner explanation

KernelStats fits delta_k(x) = -0.5*log|Sigma_k| - 0.5*(x-mu_k)'*Sigma_k^-1*(x-mu_k) + log(pi_k), estimating a SEPARATE covariance matrix Sigma_k per class: K*p(p+1)/2 covariance parameters total versus LDA's p(p+1)/2, each estimated from only that class's own rows. Optional regularization (the regularization parameter, lambda in [0,1]) shrinks each class covariance toward the identity matrix before inverting (scikit-learn's regularization parameter): Sigma_k_reg = (1-lambda)*Sigma_k + lambda*I. Because predictors are not standardized first, the same lambda is a strong nudge for a predictor measured in millimeters and a negligible one for a predictor measured in grams, which the product recommends at a small value (0.01-0.1) specifically to rescue a class whose covariance estimate is near-singular, at the deliberate cost of some flexibility.

This card explicitly reports NO discriminant scalings or LD1/LD2 score plot, and the product states the mathematical reason directly: with one shared covariance, LDA's class separation lives in a single common set of linear directions that apply to every class at once, but QDA has no shared covariance at all; each class measures distance in its OWN geometry, so there is no common linear projection to draw scores on. A predictor-space territory plot is shown instead, because the quadratic boundary is a surface, not a direction.

As with LDA, headline accuracy is always seeded k-fold cross-validated, with the product stating that QDA's EXTRA flexibility makes its in-sample number EVEN MORE optimistic than LDA's equivalent; the same assumption checks run (Shapiro-Wilk per class x predictor cell for multivariate normality, Bonferroni-corrected), but Box's M (equal covariance) is reported here only as CONTEXT rather than a gating requirement, since QDA's entire premise is not needing equal covariances in the first place: if Box's M does NOT reject, that is itself informative; it suggests LDA would likely do just as well with less estimation variance to pay for.

When to use it

Consider it when

Classes are believed to differ meaningfully in their spread, scale, or orientation (not just their location), and every class has comfortably more rows than predictors to estimate its own covariance matrix reliably.

Use caution when

Any class is small relative to the number of predictors (its covariance estimate will be noisy or singular; consider regularization or LDA instead), Box's M shows classes have similar covariance structures (LDA would likely perform just as well with less estimation variance), or you need the linear discriminant scores (LD1/LD2) for a low-dimensional separation plot, which QDA cannot provide.

Formulas and symbols

Quadratic discriminant function

δk(x)=−12log⁡∣Σk∣−12(x−μk)⊤Σk−1(x−μk)+log⁡πk\delta_k(x) = -\tfrac{1}{2}\log|\Sigma_k| - \tfrac{1}{2}(x-\mu_k)^\top \Sigma_k^{-1}(x-\mu_k) + \log \pi_k

Sigma_k a SEPARATE covariance matrix for each class k (unlike LDA's single shared Sigma); the observation is assigned to the class with the largest delta_k.

Regularized class covariance

Σ^kreg=(1−λ)Σ^k+λI\hat\Sigma_k^{\text{reg}} = (1-\lambda)\hat\Sigma_k + \lambda I

scikit-learn's reg_param: lambda in [0,1] shrinks each class covariance toward the IDENTITY matrix (its eigenvalues become (1-lambda)s + lambda), in the predictors' own units, since KernelStats does not standardize before QDA; lambda=0 is plain QDA.

Cross-validated vs in-sample accuracy (confusion matrix is in-sample)

AccuracyCV vs. Accuracyin-sample\text{Accuracy}_{\text{CV}} \ \text{vs.}\ \text{Accuracy}_{\text{in-sample}}

QDA's extra flexibility makes its in-sample accuracy even more optimistic than LDA's; the cross-validated figure is the one to trust. The confusion matrix on the card is computed from in-sample predictions (the card labels it so).

Assumptions and checks

  • Normality (of residuals, not of the raw data). QDA's curved decision boundaries are derived assuming each predictor is approximately normally distributed WITHIN each class; strong non-normality makes the boundary and the reported classification accuracy less trustworthy, especially with small classes.

    In KernelStats: Shapiro-Wilk per predictor within each class, reported directly on the card, with predictors named and skipped when there are too few or too many rows to test.

  • Unlike LDA, QDA fits a SEPARATE covariance matrix for every class rather than assuming they are equal; this flexibility costs many more parameters to estimate, so QDA needs meaningfully more data per class than LDA to estimate those covariances reliably.

    In KernelStats: Reported directly on the card as an informational note (not a pass/fail check) that QDA fits per-class covariances; the 'enough rows per class' check is the practical consequence to watch.

  • With a severely imbalanced or very small class (fewer rows than roughly 3x the number of predictors), that class's own covariance estimate is noisy, which distorts its curved decision boundary and can make the reported accuracy an unreliable summary; this risk is larger for QDA than LDA because each class's covariance is estimated separately from less data.

    In KernelStats: Checked directly: the card reports the largest/smallest class ratio (flagged above 3:1) and the smallest class's row count relative to the number of predictors (flagged below a 3x rows-per-predictor ratio).

  • Independence of observations. Rows must be independent (no repeated measures of the same subject in different rows); violated independence distorts both the fitted boundaries and the cross-validated accuracy estimate.

    In KernelStats: Not checked by KernelStats: stated directly as a standing 'Independent observations' reminder.

Alternatives

  • Linear Discriminant Analysis. Classes are believed to share a similar covariance structure, or any class is too small relative to the predictor count to estimate its own covariance reliably.
  • Logistic Regression. You have exactly two classes and want a model that makes weaker distributional assumptions than either LDA or QDA.

Worked example

Scenario

Classifying three penguin species from four body measurements, comparing QDA against LDA on the same data with 5-fold cross-validation.

Result

QDA: in-sample 98.8%, 5-fold cross-validated 98.5%; LDA: in-sample 98.8%, cross-validated 98.5%. Identical to the reported precision. Box's M rejects equal covariances (chi-square(20) = 76.8, p < .001).

Interpretation

Box's M says the species' covariance matrices differ, yet QDA's extra 20 covariance parameters buy no cross-validated accuracy at all: the difference is real but does not matter for classification. That is exactly why the choice should rest on cross-validated accuracy rather than on Box's M, and with a tie the simpler LDA is the one to report.

Dataset: penguins.csv

Common misconceptions

Misconception

QDA is always the better choice over LDA because it is strictly more flexible.

Correction

QDA's extra flexibility comes from estimating far more covariance parameters, each from a smaller amount of data (one class alone) than LDA's shared estimate uses. With small classes relative to the number of predictors, those extra parameters are estimated mostly from noise, and QDA's CROSS-VALIDATED accuracy often ends up WORSE than LDA's despite QDA's greater theoretical flexibility, a direct instance of the bias-variance trade-off, not a case where more flexible automatically means better.

Misconception

If Box's M test rejects the equal-covariance assumption, QDA must be used instead of LDA.

Correction

Box's M is known to be hypersensitive: with a large sample it rejects for covariance differences too small to matter practically. The product's own guidance is to judge Box's M at a stricter alpha = .001 (not the ordinary .05) specifically because of this hypersensitivity, and to compare the two models' actual CROSS-VALIDATED accuracies rather than let a rejected Box's M test alone dictate the choice.

References

  1. An Introduction to Statistical Learning with Applications in R (2nd ed.), Section 4.4.3, James, G., Witten, D., Hastie, T. and Tibshirani, R. (2021).
  2. The Elements of Statistical Learning, Section 4.3, Hastie, T., Tibshirani, R. and Friedman, J. (2009).