The idea: two roads to P(y | x)

A classifier needs P(y | x): how likely each class is for the point x. There are two ways to get it. A generative model learns how each class makes its points, P(x | y), and how common each class is, P(y). Then Bayes' rule turns them around into P(y | x). A discriminative model skips that and fits P(y | x), or just the boundary, directly.

Two rows. Top, generative: training points, then fit P(x | y) and P(y) per class as two Gaussian ellipses with priors, then Bayes' rule, then P(y | x). Bottom, discriminative: training points, then fit P(y | x) = σ(w·x + b) directly by gradient descent, then P(y | x).
Both roads end at P(y | x). The generative road goes through a model of the points; the discriminative road does not.

The page fits both kinds on the same 2D points: LDA and QDA (Gaussian discriminant analysis) on the generative side, logistic regression on the discriminative side. Then it tests all three on 20 points that training never saw. The table on the right keeps the scores.

LDA: means, one shared covariance, priors

LDA assumes each class is a Gaussian bell, and both bells have the same shape. Fitting it is just averaging; there is no training loop:

  • prior πk = Nk / N, the share of class k (8/16 = 0.50 here);
  • mean μk = the average of the class-k points: μ0 = (3.06, 3.30), μ1 = (6.65, 5.94);
  • shared covariance Σ = the spread of every point around its own class mean, pooled and divided by N: Σ = [0.94 0.77; 0.77 1.05].

To classify x, Bayes' rule picks the class with the larger πk·N(x; μk, Σ). Take the log of the ratio: because both classes use the same Σ, the x² terms cancel, and what is left is linear, log-odds = w·x + b with w = Σ⁻¹(μ1 − μ0). Here w = (4.47, −0.77), b = −18.11, and the boundary crosses the diagonal x1 = x2 at 4.91. (Demo: fit LDA: means, shared Σ, priors.)

So LDA's P(y = 1 | x) is σ(w·x + b), exactly the form of logistic regression. The two models differ only in how they choose w and b.

QDA: one covariance per class gives a curve

QDA lets each class have its own Σk. Now the x² terms do not cancel, so the log-odds is quadratic and the boundary is a conic: an ellipse, a parabola or a hyperbola.

Left, LDA: two ellipses of the same shape and tilt around two means, and a straight boundary between them. Right, QDA: a small tight ellipse for class 0 and a large wide one for class 1 around it, and a closed curved boundary around the small one.
Same shape for both classes: a straight boundary. A different shape per class: the boundary bends around the tighter class.

On the "tight vs wide" data, class 0 is a small blob and class 1 is spread all around it. LDA and logistic regression can only draw a line and get 15 of 20 test points right; QDA wraps a curve around class 0 and gets all 20. (Demo: tight vs wide class: QDA's curve.)

Logistic regression fits the line directly

Logistic regression never asks how the points spread. It starts at w = 0 and runs gradient descent on the log loss (η = 0.1, 1000 steps). On the two clouds it ends at w = (3.04, 0.45), b = −15.42, crossing the diagonal at 4.43. It gets all 16 training points right where LDA gets 15, and both get 19 of 20 test points right. (Demo: fit logistic regression directly; Demo: both on the same points, then test.) The training itself is shown step by step on Logistic Regression.

LDA / QDA (generative)Logistic regression (discriminative)
learnsP(x | y) and P(y)P(y | x) only
fittingaverages, in one passgradient descent, many steps
parameters hereLDA 8, QDA 113 (w1, w2, b)
assumeseach class is a Gaussianlog-odds is linear in x
can make new pointsyes, sample from the bellsno

Few points: the assumption helps

With only 3 points per class, both models separate the 6 training points perfectly. On the 20 test points LDA gets 18, logistic regression 15. Logistic regression only knows that the line must separate 6 points, and many lines do. LDA also uses where the points sit and how they spread, and on this sample that extra assumption pays off. (Demo: only 3 points per class.) Ng and Jordan showed this in general: a generative model reaches its best error with fewer samples, and a discriminative model often wins once there are many.

More parameters need more data. QDA has to estimate two covariances from 3 points each, so its curve swings wildly and it gets only 15 of 20. (Demo: QDA with only 3 points per class.) This is the bias–variance trade-off: QDA has less bias but much more variance.

An outlier: the generative fit moves

Add one class-1 point far out at (9.6, 9.4). It is on the correct side of any sensible boundary. But LDA must explain it with its Gaussian: μ1 moves to (6.98, 6.32), Σ grows to [1.34 1.26; 1.26 1.61], and the line moves from 4.91 to 5.10 on the diagonal. Test score: 19 → 17. Logistic regression barely moves (4.43 → 4.44) and still gets 19, because a point already far on its correct side has p − y ≈ 0 and almost no pull. (Demo: one far outlier.)

Grouped bars of test points right out of 20 for LDA, QDA and logistic regression on four data sets. Two clouds: 19, 18, 19. Three points per class: 18, 15, 15. Two clouds plus outlier: 17, 18, 19. Tight versus wide: 15, 20, 15.
No model wins everywhere: LDA with few points, QDA when the spreads differ, logistic regression when the Gaussian story is wrong.

Which one to use

  • Few labelled points, and the classes look roughly Gaussian: LDA. It is fast, closed-form and stable.
  • Classes with clearly different spreads and enough points per class: QDA.
  • Lots of data, outliers, or features that are not Gaussian at all (counts, yes/no flags): logistic regression.
  • Need to generate new points, or fill in a missing feature: only a generative model can.

See also Naive Bayes, another generative classifier that assumes the features are independent given the class, Logistic Regression for its gradient steps, k-means vs Gaussian Mixture and the EM algorithm for fitting the same Gaussian bells when there are no labels, and Bayes' Theorem.

What the page leaves out

Only two inputs and two classes; LDA and QDA extend to K classes, and LDA is also used to project data onto K − 1 directions (Fisher's discriminant). Covariances are maximum-likelihood estimates (divided by N) with no shrinkage; real libraries offer regularized versions (scikit-learn's shrinkage and reg_param). Logistic regression has no L2 penalty here, so on separable data its w keeps growing. The test scores come from one fixed sample, not an average over many, and cross-validation is not shown.

On the mind map

Open the Machine Learning mind mapMachine LearningLearning setup: what feedback, how to scoreLearning setupLinear models: weighted sum w·x + bLinear modelsOther classic models: trees, margins, neighboursOther classic modelsUnsupervised: find structure without labelsUnsupervisedTraining: loss, gradient, small stepTrainingNeural networks: layers of σ(W·a + b)Neural networksArchitectures: how layers share informationArchitecturesLanguage models: predict the next tokenLanguage modelsLLM speed and tuning: cheaper to run, safer to useLLM speed and tuningRetrieval and agents: give the model data and toolsRetrieval and agentsLinear regressionLinear regressionminimize squared residualsLogistic regressionLogistic regressionsigmoid of w·x + b, log lossGenerative vs DiscriminativeModel P(x|y) and use Bayes, or fit P(y|x)PerceptronPerceptronfix weights only on mistakesHopfield networkHopfield networkEnergy only falls; recall = nearest valleySupport vector machineSupport vector machinewidest margin, set by support vectorsL1 vs L2 regularizationL1 vs L2 regularizationL1 gives exact zeros, L2 shrinks allOpen the Machine Learning mind mapMachine Learningweighted sum w·x + bLinear modelsLinear regressionLinear regressionminimize squared residualsLogistic regressionLogistic regressionsigmoid of w·x + b, log lossGenerative vs DiscriminativeModel P(x|y) and use Bayes, or fit P(y|x)PerceptronPerceptronfix weights only on mistakesHopfield networkHopfield networkEnergy only falls; recall = nearest valleySupport vector machineSupport vector machinewidest margin, set by support vectorsL1 vs L2 regularizationL1 vs L2 regularizationL1 gives exact zeros, L2 shrinks all
This page on the Machine Learning mind map · 88 pages in 10 branches · open it to see the whole map and test yourself in recall mode.