Linear and Quadratic Discriminant Analysis and Logistic Regression
Anchor (Master): Hastie, Tibshirani & Friedman 2009 The Elements of Statistical Learning 2e (Springer) §4.3-4.5 (the generative/discriminative comparison, separating hyperplanes, regularized logistic regression); McCullagh & Nelder 1989 Generalized Linear Models 2e (Chapman & Hall) Ch. 2 and Ch. 4 (the exponential-dispersion family, the canonical link, Fisher scoring as IRLS); Efron 1975 The efficiency of logistic regression compared to normal discriminant analysis (JASA 70) (the asymptotic relative efficiency of the discriminative and generative fits)
Intuition Beginner
You have measurements on some objects and a label attached to each one — emails marked spam or not, tumours marked benign or malignant, irises sorted into species. A classifier is a rule that takes a fresh, unlabelled object and guesses its label from its measurements. This unit is about the simplest honest rules: ones that carve the measurement space into regions with a straight (or gently curved) boundary, one region per label.
There are two opposite ways to build such a rule. The first studies each label on its own: it asks, for each species of iris, what petals typically look like, building a little model of "what an object of this label tends to measure." Then a new object is handed to the label whose model fits it best. This is the generative way; linear and quadratic discriminant analysis are its standard members.
The second way skips the per-label modelling and goes straight for the boundary: it asks only "given these measurements, how should the odds of the labels tip?" and tunes a dial — the weights on the measurements — until the predicted odds line up with the labels actually seen. This is the discriminative way, and logistic regression is its workhorse. It never bothers to describe what a typical object of each label looks like; it only describes where to draw the line.
A surprise sits at the centre of the unit: when the generative models are matched bell-shaped clouds of the same shape, the two ways produce a boundary of the same straight form. They disagree only on how to place it — by fitting the clouds, or by fitting the line directly.
Visual Beginner
| Approach | What it models | Boundary it produces | Member methods |
|---|---|---|---|
| Generative, shared shape | a bell-shaped cloud per label, same spread | a straight line / flat plane | linear discriminant analysis |
| Generative, free shape | a bell-shaped cloud per label, each its own spread | a curved boundary | quadratic discriminant analysis |
| Discriminative | only the odds of the labels given the data | a straight line / flat plane | logistic regression |
The picture to keep: two clouds of labelled points. If the clouds have the same shape, the fair dividing line between them is straight; if one cloud is fatter than the other, the fair divider bends. Linear discriminant analysis and logistic regression both draw the straight line, by different means; quadratic discriminant analysis draws the curve.
Worked example Beginner
Two kinds of fish are sorted by a single measurement, body length in centimetres. Kind A lengths average , kind B lengths average , and both kinds spread the same amount around their average. The two kinds are equally common in the catch. A fish cm long arrives. Which kind is it?
The fair rule, when the two clouds have the same shape and are equally common, is the simplest one: assign the fish to whichever average it is closer to. The midpoint between the averages is . A length above leans toward kind B; a length below leans toward kind A.
Our fish is cm. Its distance to the kind-A average is . Its distance to the kind-B average is . The fish is closer to kind B, so the rule calls it kind B.
Now change the catch. Suppose kind A is four times as common as kind B. Being common shifts the boundary toward the rarer kind: you need stronger length-evidence to overrule the fact that most fish are kind A. The boundary moves up from to about for this spread, but our cm fish sits well above even the shifted line, so it is still called kind B.
What this tells us: with equal, same-shaped clouds the boundary is a single cut-point halfway between the averages, and how common each kind is slides that cut-point toward the rarer kind. Everything later in the unit is this one cut-point, dressed up for many measurements at once.
Check your understanding Beginner
Formal definition Intermediate+
Let be a feature-label pair with and . Write the prior class probabilities and the class-conditional densities . By Bayes' rule the posterior is .
Definition (Bayes classifier). Under - loss the Bayes classifier assigns
It minimises the misclassification probability among all rules; its risk is the Bayes rate. The set is the decision boundary between classes and .
The generative model: discriminant analysis. Take Gaussian class-conditionals 26.03.01. Comparing across and discarding the -free term gives the quadratic discriminant function
and the rule is quadratic discriminant analysis (QDA): its boundaries are quadric surfaces. If all classes share a covariance , the quadratic term is common to every class and cancels, leaving the linear discriminant function
linear in . The rule is linear discriminant analysis (LDA), with hyperplane boundaries. Parameters are estimated by their maximum-likelihood plug-ins 45.01.04: , , and for LDA the pooled .
The discriminative model: logistic regression. For classes coded , posit the logit-linear (log-odds) model
with the logistic (sigmoid) function. Absorbing the intercept into and the constant into , the log-likelihood of an i.i.d. sample is
and the MLE is found by maximising it. The multinomial (softmax) extension for classes fixes a reference class and models , giving .
Counterexamples to common slips
- LDA is not nearest-centroid. The rule "assign to the nearest class mean in Euclidean distance" matches LDA only when and the priors are equal. In general the relevant distance is the Mahalanobis distance , and unequal priors shift the boundary by .
- The logit is the log-odds, not the log-probability. Modelling as linear violates the constraint ; the logit maps onto all of , which is what makes a linear model on it coherent.
- More classes does not always favour QDA. QDA estimates a separate per class — covariance parameters — and on small samples this variance can swamp the bias LDA pays for pooling; the pooled estimate is often the better classifier despite its wrong shared-covariance assumption.
- Perfect separation is not a perfect fit. If a hyperplane separates the two classes with no overlap, the logistic likelihood has no maximiser: drives the fitted probabilities to and the likelihood up without bound. The MLE fails to exist exactly when the data are linearly separable.
Key theorem with proof Intermediate+
The signature computational result is that the maximum-likelihood fit of logistic regression is a sequence of weighted least-squares fits: Newton-Raphson on the log-likelihood is iteratively reweighted least squares (IRLS), reusing the normal-equations machinery of the linear model 45.06.01 with a diagonal weight matrix that the current fitted probabilities supply. The result follows Hastie, Tibshirani & Friedman [Hastie 2009] §4.4 and McCullagh & Nelder [McCullagh 1989] Ch. 4.
Theorem (logistic regression by IRLS). Let have rows (intercept absorbed) and full column rank, . With , , and the diagonal weight matrix , the gradient and Hessian of the log-likelihood are
The Newton-Raphson update equals the weighted least-squares solution
where is the working response (the adjusted dependent variable). Each step solves a weighted least-squares problem; hence the name.
Proof. Differentiate . The -th summand has gradient , since . Summing, .
For the Hessian, use , so . Then
with . The weights are positive whenever , so , and full column rank of makes , hence invertible.
Substitute into the Newton step:
Factor and write , so
which is with . This is the normal equation for the weighted least-squares regression of on with weights .
Bridge. The proof's engine is that the Hessian is the weighted Gram matrix of the linear model 45.06.01 with the Bernoulli variance supplying the weights, so each Newton step is the generalized-least-squares solve of that unit applied to the working response . This is exactly the Fisher-scoring identity of 45.01.04 specialised to the canonical-link binomial: because the logistic link is canonical, the observed and expected information coincide and Newton equals Fisher scoring, which is the foundational reason the update reduces to clean weighted least squares rather than something messier. The negative log-likelihood is convex — makes have a positive-semidefinite Hessian everywhere — so the iteration converges to the unique global maximiser whenever one exists. The result builds toward the regularized fits below, where adding a penalty restores existence and uniqueness on separated or high-dimensional data, and it appears again in the generative/discriminative comparison: putting these together, LDA and logistic regression share the linear log-odds form , and the central insight of the unit is that they differ only in how that single linear function is fitted — generatively from the Gaussian clouds, or discriminatively by this IRLS maximisation of the conditional likelihood.
Exercises Intermediate+
Lean formalization Intermediate+
Mathlib does not host the classification layer, so no module is wired in (lean_status: none). The intended statements — the convexity of the logistic deviance and the IRLS identity — would read roughly as follows.
-- Intended shape; not part of the current Babel Bible Lean build.
-- Requires: the logistic function, a design matrix X, Bernoulli responses y,
-- and the convex-analysis API (`ConvexOn`, `StrictConvexOn`).
variable {n p : ℕ} (X : Matrix (Fin n) (Fin p) ℝ) (y : Fin n → ℝ)
noncomputable def sigmoid (t : ℝ) : ℝ := 1 / (1 + Real.exp (-t))
-- negative log-likelihood (deviance) of logistic regression
noncomputable def negLogLik (β : Fin p → ℝ) : ℝ :=
∑ i, (Real.log (1 + Real.exp ((X i) ⬝ᵥ β)) - y i * ((X i) ⬝ᵥ β))
-- convexity of the deviance: Hessian Xᵀ W X is PSD with W = diag(pᵢ(1-pᵢ))
theorem negLogLik_convex : ConvexOn ℝ Set.univ (negLogLik X y) := by
sorry
-- full column rank upgrades convex to strictly convex (unique MLE when it exists)
theorem negLogLik_strictConvex (hX : Function.Injective X.mulVec) :
StrictConvexOn ℝ Set.univ (negLogLik X y) := by
sorrythe Mathlib gap analysis records what is missing: the Bayes-rule optimality for - loss, the LDA/QDA discriminant derivation from the Gaussian density, Fisher's between/within generalised eigenproblem, the IRLS update , and the separation/non-existence dichotomy of the MLE.
Advanced results Master
The generative and discriminative routes both produce a posterior of the same functional form, and identifying where they part is the organising fact of the unit.
Theorem 1 (LDA posterior is logistic). Under shared-covariance Gaussian class-conditionals with two classes, the LDA posterior log-odds is exactly linear:
This is the logistic model. LDA and logistic regression therefore posit the same linear log-odds; they differ only in how are estimated. LDA fits the full joint likelihood — the generative likelihood, which the Gaussian-plus-prior parameters maximise in closed form — whereas logistic regression fits the conditional likelihood , leaving the marginal of unmodelled. The generative fit uses the marginal information in the (the shape and separation of the clouds) that the conditional fit discards.
Theorem 2 (efficiency-robustness trade). When the Gaussian model holds, LDA is asymptotically more efficient: it uses more of the data's information, and Efron [Efron 1975] showed logistic regression is roughly one-half to two-thirds as efficient in the regimes he computed. When the Gaussian model fails — skewed features, outliers, qualitative predictors — the LDA covariance and mean estimates are biased and its boundary degrades, while logistic regression, committing to nothing about the marginal of , remains consistent for the log-odds whenever the log-odds is genuinely linear. The discriminative method buys robustness with the efficiency it forgoes.
Theorem 3 (Fisher's reduced-rank discriminant). With classes in , the class means span an affine subspace of dimension at most . Fisher's discriminant seeks the directions maximising the Rayleigh quotient , where is the between-class scatter and the pooled within-class scatter. The successive maximisers are the leading generalised eigenvectors of the pencil 01.01.19; equivalently, whiten by so the problem becomes the ordinary eigenproblem of the transformed . Projecting onto the leading such directions and applying LDA in the reduced space is reduced-rank LDA, a supervised dimension reduction that loses no LDA information when .
Theorem 4 (regularized logistic regression). Adding a penalty to the deviance,
serves two ends. The (ridge) penalty makes the objective strictly convex and coercive, so the minimiser exists and is unique even under linear separation or when , shrinking coefficients toward zero. The (lasso) penalty additionally produces exact zeros, performing simultaneous fitting and variable selection 45.06.06; the optimisation is convex but non-smooth, solved by coordinate descent or proximal methods rather than plain Newton. Both penalties trade a controlled bias for variance reduction, the same bias-variance bargain that shrinkage strikes for the linear model 45.06.01.
Synthesis. The foundational reason the whole subject coheres is the shared linear log-odds : LDA derives it from matched Gaussian clouds and logistic regression posits it directly, so the two are dual estimators of one boundary — generative versus discriminative fits of the same model. This is exactly the efficiency-robustness duality that Efron quantified: the generative fit harvests the marginal information in and wins on efficiency when its Gaussian assumption is true, while the discriminative fit, indifferent to that marginal, wins on robustness when it is false, and putting these together explains why neither dominates in practice. The central insight extends to dimension reduction: Fisher's quotient is the generalised eigenproblem of 01.01.19 wearing statistical clothing, the between/within scatters playing the roles of the two quadratic forms, so supervised projection and classification are one optimisation seen twice. The IRLS engine generalises beyond the logit — every canonical-link generalized linear model fits by the same weighted least squares, with the Bernoulli variance replaced by the model's variance function — and the bridge to the high-dimensional regime is regularization, which restores the existence the separated-data MLE loses and connects classification to the sparsity theory of 45.06.06. The quadratic case sits at the boundary of this picture: dropping the shared-covariance assumption breaks the linearity, turns the discriminant quadratic, and forfeits the logistic identification, which is the precise sense in which QDA is the generative method without a matching discriminative twin.
Full proof set Master
Proposition 1 (Bayes-rule optimality for - loss). Among all classifiers , the Bayes classifier minimises the misclassification probability .
Proof. Condition on . For any rule , . This conditional error is minimised, pointwise in , by choosing to maximise , which is the Bayes rule . Taking expectation over , , since the integrand is minimised pointwise.
Proposition 2 (the QDA discriminant and its cancellation to LDA). For Gaussian class-conditionals , the Bayes rule is with the quadratic discriminant ; if , reduces to a linear function of .
Proof. The Bayes rule maximises . Expanding the Gaussian log-density,
The term is -free and drops from the , leaving as stated. When , expand . The quadratic and the constant are -free and drop, leaving , linear in .
Proposition 3 (gradient, Hessian, and convexity of the logistic deviance). With and , and ; under full column rank of the inequality is strict, so is strictly convex.
Proof. The per-observation log-likelihood is . Its gradient is using , and its second derivative is using . Summing gives and . For any , since each weight is positive, so is convex; equality needs for every , i.e. , which under full column rank forces . Hence and is strictly convex, with at most one minimiser.
Proposition 4 (IRLS = Newton-Raphson). The Newton step on equals the weighted least-squares fit with working response .
Proof. As established in the Key theorem: . Writing and , factor out to obtain , the weighted normal equation for regressing on with weights .
Proposition 5 (non-existence of the MLE under separation; ridge restores it). If the data are linearly separable then is not attained. For any the penalised objective attains a unique maximum.
Proof. Suppose separates: when and when (intercept absorbed). For and , each term as because on the points and on the points; each term is negative for finite , so without reaching it, and no finite gives . Thus the supremum is unattained. For the penalised objective, is convex (Proposition 3) and is strictly convex and coercive, so as and is strictly convex; a strictly convex coercive function on attains a unique minimum.
Connections Master
The linear model and its hat-matrix least-squares machinery
45.06.01is reused verbatim inside IRLS: each Newton step is the weighted least-squares solve , the generalized-least-squares normal equation of that unit with the Bernoulli variances as weights and the working response as the response, so logistic fitting is a loop over linear-model fits.The maximum-likelihood and Fisher-scoring theory
45.01.04supplies the existence-and-uniqueness logic here: the logistic log-likelihood is concave with Hessian , and because the logit is the canonical link the observed and expected information coincide, so the Newton iteration of that unit is exactly the IRLS of this one, and the moment-matching score equation is its specialisation.Newton's method for optimization
44.03.03is the algorithmic backbone of the discriminative fit: IRLS is Newton-Raphson on the concave deviance, inheriting that unit's local quadratic convergence, and the convexity established here is what upgrades local convergence to global convergence toward the unique maximiser.Regularized regression and the lasso
45.06.06extend directly to classification: the penalty restores the existence the separated-data logistic MLE loses, while the penalty performs variable selection on the coefficients, the corner geometry and subgradient conditions of that unit carrying over to the logistic deviance in place of the squared-error loss.The multivariate normal and covariance machinery
26.03.01is the generative engine of LDA and QDA: the class-conditional Gaussian densities, their Mahalanobis exponents, and the pooled covariance estimate are the objects whose log-ratio produces the discriminant functions, and the same Gaussian transformation rules govern the sampling behaviour of the plug-in estimates.The simultaneous diagonalisation of two quadratic forms and the generalised eigenvalue problem
01.01.19is precisely Fisher's reduced-rank discriminant: maximising the between/within Rayleigh quotient is the generalised eigenproblem , and whitening by is the simultaneous-diagonalisation step that turns supervised dimension reduction into an ordinary eigenproblem.
Historical & philosophical context Master
Linear discriminant analysis originates with R. A. Fisher's 1936 study of iris measurements, The use of multiple measurements in taxonomic problems [Fisher 1936], which posed the problem of finding the linear combination of features that best separates known groups and solved it through the between-to-within scatter ratio now bearing his name. Fisher framed it without an explicit probability model — as an optimal projection — and the equivalence to the Bayes rule under shared-covariance Gaussians was recognised afterward, by Welch and others, tying the geometric and the generative pictures together. The quadratic generalisation, allowing each class its own covariance, follows directly from the same Gaussian Bayes rule and was standard by the mid-century multivariate-analysis literature.
Logistic regression has a separate lineage. The logistic function was studied by Verhulst in the nineteenth century as a population-growth curve and revived for bioassay by Berkson in the 1940s, who advocated the logit against the then-dominant probit. Its maturation as a general regression method came through the unifying framework of generalized linear models, introduced by Nelder and Wedderburn in 1972 and consolidated in McCullagh and Nelder's Generalized Linear Models [McCullagh 1989], which identified the logit as the canonical link for binomial responses and the Fisher-scoring fit as iteratively reweighted least squares. The generative-versus-discriminative comparison was sharpened by B. Efron's 1975 calculation [Efron 1975] of the asymptotic relative efficiency of logistic regression against normal discriminant analysis, quantifying the cost the conditional likelihood pays when the Gaussian model is true and, implicitly, the robustness it gains when that model is false.
Bibliography Master
@book{hastie2009elements,
author = {Hastie, Trevor and Tibshirani, Robert and Friedman, Jerome},
title = {The Elements of Statistical Learning: Data Mining, Inference, and Prediction},
edition = {2},
publisher = {Springer},
year = {2009},
note = {Chapter 4, linear methods for classification}
}
@book{mccullagh1989generalized,
author = {McCullagh, Peter and Nelder, John A.},
title = {Generalized Linear Models},
edition = {2},
publisher = {Chapman and Hall},
year = {1989}
}
@article{fisher1936use,
author = {Fisher, Ronald A.},
title = {The use of multiple measurements in taxonomic problems},
journal = {Annals of Eugenics},
volume = {7},
number = {2},
pages = {179--188},
year = {1936}
}
@article{efron1975efficiency,
author = {Efron, Bradley},
title = {The efficiency of logistic regression compared to normal discriminant analysis},
journal = {Journal of the American Statistical Association},
volume = {70},
number = {352},
pages = {892--898},
year = {1975}
}
@article{nelder1972generalized,
author = {Nelder, John A. and Wedderburn, Robert W. M.},
title = {Generalized linear models},
journal = {Journal of the Royal Statistical Society, Series A},
volume = {135},
number = {3},
pages = {370--384},
year = {1972}
}
@article{berkson1944application,
author = {Berkson, Joseph},
title = {Application of the logistic function to bio-assay},
journal = {Journal of the American Statistical Association},
volume = {39},
number = {227},
pages = {357--365},
year = {1944}
}