Naive Bayes, LDA & QDA, In Full Depth
Every classifier so far — logistic regression, SVM, KNN — is discriminative: it learns a boundary directly, without ever modeling what each class's data actually looks like. This page covers the alternative: generative classifiers, which model each class's distribution explicitly, then use Bayes' theorem to classify.
Discriminative vs. Generative
- Discriminative models learn directly — "given this input, what's the probability of each class?"
- Generative models learn for each class — "if this were really class , what would the data look like?" — plus the class prior , then combine via Bayes' theorem:
Since is the same regardless of which class you're evaluating, classification just picks whichever class maximizes the numerator: .
Naive Bayes
The "naive" assumption: features are conditionally independent given the class — . This is almost never literally true (word co-occurrence in text, correlated pixels in images) — yet Naive Bayes remains a fast, surprisingly strong baseline, especially for text classification, because getting the relative ranking between classes right doesn't actually require the independence assumption to be true, only that violating it doesn't happen to favor the wrong class.
Three variants, differing in what is assumed to look like:
- Gaussian Naive Bayes: assumes each feature is normally distributed within each class — . The natural choice for continuous features.
- Multinomial Naive Bayes: assumes features are counts (e.g. word frequencies in a document) drawn from a multinomial distribution — the standard choice for text classification with bag-of-words features.
- Bernoulli Naive Bayes: assumes features are binary (e.g. "does this word appear at all, yes/no") — used for text when only presence/absence matters, not frequency.
Training is just counting: estimate each class's prior as its frequency in the training set, and each from the relevant sample statistics (mean/variance for Gaussian, counts for Multinomial/Bernoulli) — no iterative optimization at all, which is exactly why Naive Bayes trains almost instantly even on large datasets.
LDA: Linear Discriminant Analysis
LDA is a specific generative model: assumes each class's features follow a multivariate Gaussian, and — critically — that every class shares the same covariance matrix , differing only in their means .
Under this assumption, the log-ratio works out to be linear in — the quadratic terms from the Gaussian density cancel exactly because both classes share the same . That's why LDA produces a straight-line boundary:
QDA: Quadratic Discriminant Analysis
Drop LDA's shared-covariance assumption — let each class have its own covariance matrix . Now the quadratic terms in the log-ratio no longer cancel, producing a genuinely curved boundary:
Toggle between the two directly on the same real data, with each boundary computed live from real fitted means and covariances rather than pre-rendered:
LDA vs. QDA
More flexible isn't automatically better — QDA has far more parameters to estimate (a full covariance matrix per class instead of one shared matrix), so it needs proportionally more data to estimate them reliably. With limited data, LDA's extra assumption acts as a form of regularization: it accepts a bit more bias (forcing a linear boundary even if the true boundary curves slightly) in exchange for much lower variance in the estimated parameters. The same bias-variance tradeoff appears here as everywhere else in this curriculum (Model Evaluation & Metrics) — just expressed through a modeling assumption instead of a regularization hyperparameter.
Naive Bayes vs. LDA vs. QDA
| Naive Bayes | LDA | QDA | |
|---|---|---|---|
| Feature independence assumed? | Yes | No (models full covariance) | No |
| Covariance shared across classes? | N/A (independent features) | Yes | No, per-class |
| Boundary shape | Depends on distribution choice | Linear | Quadratic (curved) |
| Parameters to estimate | Fewest | Moderate | Most |
| Best when | Many features, limited data (esp. text) | Gaussian-ish classes, similar spread | Gaussian-ish classes, genuinely different spread per class |
Minimal Implementation
Gaussian Naive Bayes, matching the derivation above directly:
Next: SGD Classifier & Regressor — the generic "any linear model, trained via SGD" framing that ties the linear-model family together.