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.
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.
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) | |
|---|---|---|
| learns | P(x | y) and P(y) | P(y | x) only |
| fitting | averages, in one pass | gradient descent, many steps |
| parameters here | LDA 8, QDA 11 | 3 (w1, w2, b) |
| assumes | each class is a Gaussian | log-odds is linear in x |
| can make new points | yes, sample from the bells | no |
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.)
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.