advanced supervised-learning 55 min read

Naive Bayes

Generative classification via the conditional-independence factorization — the Bayes-optimal classifier and its plug-in approximation, three classical variants (Gaussian, Multinomial, Bernoulli), Laplace smoothing as conjugate Bayesian update, the Ng–Jordan discriminative-vs-generative asymptotics that explain why naive Bayes wins at small n, calibration repair via Platt and isotonic, and structured extensions (TAN, AODE) that relax the independence assumption.

§1. From features to a class label: the generative recipe

§1.1 A spam-filter vignette

Suppose we receive an email whose body, after tokenization, reduces to the bag {"buy","now","click","here"}\{\text{"buy"}, \text{"now"}, \text{"click"}, \text{"here"}\}. Is it spam? A reasonable answer needs three ingredients: the prior probability that any email is spam π1=P(Y=spam)\pi_1 = P(Y = \text{spam}); the generative description of what tokens spam emails tend to contain p(xY=spam)p(\mathbf{x} \mid Y = \text{spam}); the same for ham p(xY=ham)p(\mathbf{x} \mid Y = \text{ham}). Bayes’ rule assembles them into the posterior we actually want:

P(Y=spamx)  =  p(xY=spam)π1p(xY=spam)π1+p(xY=ham)π0.P(Y = \text{spam} \mid \mathbf{x}) \;=\; \frac{p(\mathbf{x} \mid Y = \text{spam})\,\pi_1}{p(\mathbf{x} \mid Y = \text{spam})\,\pi_1 + p(\mathbf{x} \mid Y = \text{ham})\,\pi_0}.

The decision rule that minimizes the expected number of misclassifications (we’ll see in §3 that this is the 0/1-loss-optimal rule) is just predict the class with the larger posterior. Bayes’ rule is the entire framework. The “naive” in naive Bayes refers to a structural assumption about the likelihood p(xY)p(\mathbf{x} \mid Y) that makes the right-hand side estimable from data; before we get there, let’s see why it’s needed.

§1.2 Bayes’ rule for classification

Fix a finite label set Y={0,1,,K1}\mathcal{Y} = \{0, 1, \ldots, K-1\}. Given an observation xX\mathbf{x} \in \mathcal{X} (continuous, discrete, or mixed), Bayes’ rule writes the posterior in terms of the prior and the class-conditional likelihood:

P(Y=kX=x)  =  p(xY=k)P(Y=k)j=0K1p(xY=j)P(Y=j)    p(xY=k)πk,P(Y = k \mid \mathbf{X} = \mathbf{x}) \;=\; \frac{p(\mathbf{x} \mid Y = k)\,P(Y = k)}{\sum_{j=0}^{K-1} p(\mathbf{x} \mid Y = j)\,P(Y = j)} \;\propto\; p(\mathbf{x} \mid Y = k)\,\pi_k,

where πk:=P(Y=k)\pi_k := P(Y = k) and the denominator p(x)=jp(xj)πjp(\mathbf{x}) = \sum_j p(\mathbf{x} \mid j) \pi_j is the marginal-evidence normalization. The proportionality is the form we’ll use everywhere — the denominator is the same across kk and drops out of any argmax.

Decision rule (Bayes classifier under 0/1 loss; see §3.1 for the derivation). Predict y^(x)=argmaxkP(Y=kx)=argmaxkp(xk)πk\hat y(\mathbf{x}) = \arg\max_k P(Y = k \mid \mathbf{x}) = \arg\max_k \, p(\mathbf{x} \mid k)\,\pi_k.

This is the cleanest classifier in all of statistics. The only obstacle is that we don’t know p(xk)p(\mathbf{x} \mid k) and πk\pi_k from data — we have to estimate them. Estimating πk\pi_k is easy (count class labels). Estimating p(xk)p(\mathbf{x} \mid k) is, in general, very hard, which brings us to the next subsection.

At (π = 0.30, LR = 2.50): P(Y = 1 | x) = 0.517. The decision threshold (P = 1/2) lies at LR* = (1 − π) / π = 2.33.

§1.3 Why p(xy)p(\mathbf{x} \mid y) is intractable in high dimensions

Suppose every feature is binary (xj{0,1}x_j \in \{0, 1\}) and there are dd of them. A full joint distribution over x\mathbf{x} given yy has 2d12^d - 1 free parameters per class. At d=30d = 30 — a tiny problem by modern standards — that’s already over 10910^9 parameters per class. Even with n=106n = 10^6 training examples, only a vanishing fraction of the 2d2^d joint configurations are ever observed; the empirical estimate of p(xy)p(\mathbf{x} \mid y) is zero almost everywhere.

The same issue afflicts continuous features. Estimating a dd-dimensional density p(xy)p(\mathbf{x} \mid y) nonparametrically — by KDE, say — requires sample size nhdn \asymp h^{-d} to keep variance under control, where hh is the bandwidth. The curse-of-dimensionality rate from kernel-regression §6 applies here too: density estimation is rate n4/(4+d)n^{-4/(4+d)}, which collapses to nothing past d10d \approx 10.

We need to break the high-dimensional density estimation problem into a sequence of tractable low-dimensional problems. The naive Bayes assumption is the simplest possible way to do this, and we’ll see in §3.4 / §8 / §10 that it’s also surprisingly effective for classification (not so much for calibrated probability estimation, but classification is what we asked for).

§1.4 The conditional-independence assumption

The naive Bayes assumption is that, given the class label, the features are independent:

p(xy)  =  j=1dp(xjy).\boxed{\quad p(\mathbf{x} \mid y) \;=\; \prod_{j=1}^{d} p(x_j \mid y). \quad}

Two things this is not. First, it’s not saying that the features are independent unconditionally — typically they aren’t, because they’re all driven by the class label. Second, it’s not saying that the features are actually conditionally independent in the data-generating distribution; in real applications they almost never are. The assumption is a modeling choice. We’re going to plug a structured, easy-to-estimate factorized likelihood into Bayes’ rule and see what happens.

The estimation problem now decomposes: instead of one dd-dimensional density per class, we have dd one-dimensional densities per class. For continuous features under a Gaussian per-coordinate model that’s 2d2d parameters per class (mean and variance); for binary features under a Bernoulli per-coordinate model it’s dd parameters per class (rates). Total parameter count grows linearly in dd rather than exponentially. This is the central trade — accept structural bias from the wrong-independence assumption in exchange for tractable estimation at high dd.

§1.5 Roadmap

The rest of the notebook answers four questions about this classifier.

What does it look like? §2 formalizes the product-factorization estimator and the argmax-of-log decision rule, shows the directed-graphical-model picture, and locates naive Bayes in the generative-vs-discriminative taxonomy.

Is it any good? §3 develops Bayes-optimal classifier theory — the 0/1-loss decomposition, the Bayes risk floor, the excess-risk bound for plug-in classifiers, and the preview of why NB ranks classes well even when it calibrates poorly.

How do we fit it? §§4–5 work out MLE for three classical variants (Gaussian, Multinomial, Bernoulli) and the implementation tricks (log-sum-exp, var-smoothing, sparse-matrix multiplication). §6 adds Laplace smoothing as a Bayesian conjugate update.

When is it the right tool? §7 is the Ng–Jordan (2002) discriminative-vs-generative asymptotic comparison — the headline theoretical result on when NB wins (small nn) and when logistic regression wins (large nn). §8 covers calibration repair. §9 covers structure-learning extensions (TAN, AODE) that relax the strict-independence assumption. §10 closes with text-classification applications and forward pointers.

§2. The naive Bayes classifier

§2.1 The product factorization and the decision rule

Plugging the naive-Bayes factorization into the proportional Bayes rule from §1.2:

P^(Y=kx)    πkj=1dp(xjY=k).\widehat{P}(Y = k \mid \mathbf{x}) \;\propto\; \pi_k \prod_{j=1}^{d} p(x_j \mid Y = k).

The decision rule predicts y^(x)=argmaxkπkjp(xjk)\hat y(\mathbf{x}) = \arg\max_k \pi_k \prod_j p(x_j \mid k). We almost never compute the product directly — products of many small numbers underflow float64 quickly (already at d700d \approx 700 for typical token-probability scales). We work in log-space throughout:

y^(x)  =  argmaxklogπk+j=1dlogp(xjY=k).\hat y(\mathbf{x}) \;=\; \arg\max_k \, \log\pi_k + \sum_{j=1}^{d} \log p(x_j \mid Y = k).

For probabilities (rather than just class labels) we use the log-sum-exp identity:

P(Y=kx)  =  exp(k)jexp(j)  =  exp ⁣(kLSE()),P(Y = k \mid \mathbf{x}) \;=\; \frac{\exp(\ell_k)}{\sum_{j} \exp(\ell_j)} \;=\; \exp\!\bigl(\ell_k - \mathrm{LSE}(\boldsymbol\ell)\bigr),

where k:=logπk+jlogp(xjk)\ell_k := \log\pi_k + \sum_j \log p(x_j \mid k) and LSE():=logjexp(j)\mathrm{LSE}(\boldsymbol\ell) := \log\sum_j \exp(\ell_j). The numerically-safe LSE subtracts the max first: LSE()=maxjj+logjexp(jmaxjj)\mathrm{LSE}(\boldsymbol\ell) = \max_j \ell_j + \log\sum_j \exp(\ell_j - \max_j \ell_j).

§2.2 The naive Bayes classifier as a log-linear model

Substitute exponential-family per-feature likelihoods p(xjy)=hj(xj)exp(ηjyTj(xj)Aj(ηjy))p(x_j \mid y) = h_j(x_j) \exp\bigl(\eta_{jy}^\top T_j(x_j) - A_j(\eta_{jy})\bigr) into the log-posterior:

logP^(Y=kx)  =  logπkbiask  +  j=1d[ηjkTj(xj)Aj(ηjk)]+const.\log\widehat{P}(Y = k \mid \mathbf{x}) \;=\; \underbrace{\log \pi_k}_{\text{bias}_k} \;+\; \sum_{j=1}^{d} \Bigl[\, \eta_{jk}^\top T_j(x_j) - A_j(\eta_{jk}) \,\Bigr] + \text{const}.

The terms not depending on kk drop in the argmax. What remains is linear in the sufficient statistics Tj(xj)T_j(x_j) with class-dependent weights ηjk\eta_{jk}. Naive Bayes is a log-linear classifier in the sufficient-statistic representation. This is the formal sense in which Gaussian NB shares a decision-rule family with linear discriminant analysis (LDA), and Multinomial NB shares one with multiclass logistic regression. The Ng–Jordan §7 comparison is meaningful precisely because the two classifiers occupy the same hypothesis class — the difference is in how the parameters are estimated, not in what functions the classifier can express.

§2.3 The naive Bayes directed graphical model

Naive Bayes corresponds to a particular directed acyclic graph (DAG): the label node YY is the parent of every feature node XjX_j, and there are no edges between the features.

        Y
      / | \
     /  |  \
    X_1 X_2 ... X_d

The joint factorizes as p(y,x)=p(y)jp(xjy)p(y, \mathbf{x}) = p(y) \prod_j p(x_j \mid y), which is exactly the naive-Bayes assumption. The graph encodes a set of conditional independence statements: XiXjYX_i \perp X_j \mid Y for all iji \ne j. (Unconditionally, the features are typically not independent — knowing X1X_1 tells you something about YY, which tells you something about X2X_2.)

This graphical view makes the §9 extensions natural: relax the independence by adding edges between the XjX_j. A tree over the features (with YY still the universal parent) is the Tree-Augmented Naive Bayes (TAN, Friedman–Geiger–Goldszmidt 1997). A complete graph would recover the full joint and lose the tractability gain.

Two Bayesian-network structures: naive Bayes (left, Y → X_i with no edges among features) vs a tree-augmented variant.
Two Bayesian-network structures: naive Bayes (left, Y → X_i with no edges among features) vs a tree-augmented variant.
Parameters to specify (binary features, binary class): 11. At d = 5, the full joint requires 63 parameters; the naive factorization requires only 11.

§2.4 Generative vs discriminative

Naive Bayes is a generative model: it estimates the joint distribution p(x,y)=p(xy)p(y)p(\mathbf{x}, y) = p(\mathbf{x} \mid y)\,p(y) and derives the conditional p(yx)p(y \mid \mathbf{x}) via Bayes’ rule. The competing approach — used by logistic regression, support vector machines, neural networks — is discriminative: estimate p(yx)p(y \mid \mathbf{x}) directly, never modeling p(x)p(\mathbf{x}) at all.

Why does the distinction matter?

  • Sample complexity. Generative models have more parameters to fit (they model x\mathbf{x} too), so they typically need more data to reach their asymptotic accuracy if no shortcut is used. Naive Bayes is the shortcut: factorize the joint, restrict to O(d)O(d) parameters, get the small-nn advantage. §7 develops this carefully (Ng–Jordan 2002).
  • Asymptotic bias. Discriminative methods are asymptotically optimal for prediction under the class of conditional models they can express. Generative methods may have lower asymptotic accuracy if the joint model is misspecified — but naive Bayes’ joint model is always misspecified on real data, so this asymptotic gap is the price of the small-nn advantage.
  • What you get for free. Generative models give you p(x)p(\mathbf{x}) as a byproduct — useful for anomaly detection, missing-feature imputation, and synthetic-example generation. Discriminative models don’t, by design.

The takeaway: NB and logistic regression occupy the same hypothesis class but estimate the parameters differently, and that difference produces the small-nn vs large-nn trade we’ll see in §7.

§3. Bayes-optimal classifier theory

§3.1 The 0/1-loss decomposition

For a classifier h:XYh : \mathcal{X} \to \mathcal{Y} trained on data and evaluated on a fresh pair (X,Y)(\mathbf{X}, Y) from the true joint distribution, the 0/1 risk is

R(h)  :=  E(X,Y)[1{h(X)Y}]  =  Pr(h(X)Y).R(h) \;:=\; \mathbb{E}_{(\mathbf{X}, Y)} \bigl[\mathbb{1}\{h(\mathbf{X}) \ne Y\}\bigr] \;=\; \Pr\bigl(h(\mathbf{X}) \ne Y\bigr).

The Bayes classifier hh^\star minimizes this risk:

h(x)  =  argmaxkP(Y=kX=x).h^\star(\mathbf{x}) \;=\; \arg\max_{k} P(Y = k \mid \mathbf{X} = \mathbf{x}).

Theorem (Bayes-classifier optimality). R(h)R(h)R(h^\star) \le R(h) for every measurable hh.

Proof.

Fix x\mathbf{x}. Then Pr(h(X)=YX=x)=kP(Y=kx)1{h(x)=k}\Pr(h(\mathbf{X}) = Y \mid \mathbf{X} = \mathbf{x}) = \sum_k P(Y = k \mid \mathbf{x}) \mathbb{1}\{h(\mathbf{x}) = k\}. This sum picks out the single term P(Y=h(x)x)P(Y = h(\mathbf{x}) \mid \mathbf{x}) — the prior-times-likelihood of the class hh named. The maximum over h(x)h(\mathbf{x}) is therefore maxkP(Y=kx)\max_k P(Y = k \mid \mathbf{x}), attained by hh^\star. Taking expectations over X\mathbf{X} preserves the inequality.

The Bayes risk (or Bayes error rate, irreducible error) is

R  :=  R(h)  =  EX[1maxkP(Y=kX)].R^\star \;:=\; R(h^\star) \;=\; \mathbb{E}_{\mathbf{X}} \Bigl[\, 1 - \max_k P(Y = k \mid \mathbf{X}) \,\Bigr].

Any classifier — naive Bayes, logistic regression, the latest deep net — is at best RR^\star. The gap is irreducible: it’s the inherent randomness in YY given X\mathbf{X}, which no amount of data or model complexity can erase.

§3.2 The Bayes risk floor — what no classifier can beat

Let η(x):=P(Y=1X=x)\eta(\mathbf{x}) := P(Y = 1 \mid \mathbf{X} = \mathbf{x}) be the true posterior in a two-class problem. Then R=E[min(η(X),1η(X))]R^\star = \mathbb{E}[\min(\eta(\mathbf{X}), 1 - \eta(\mathbf{X}))]. The minimum picks the smaller of the two posterior probabilities — exactly the per-point misclassification rate of the Bayes classifier. When η(x){0,1}\eta(\mathbf{x}) \in \{0, 1\} for all x\mathbf{x} — labels are deterministic functions of features — the Bayes risk is zero. When η(x)1/2\eta(\mathbf{x}) \equiv 1/2 — the label is independent of the features — the Bayes risk is 1/21/2.

Two facts to internalize. (1) Bayes risk is a property of the data distribution, not of any classifier. It quantifies how much information the features carry about the label. (2) It’s the right benchmark. Reporting “our classifier achieves 5% error” is uninformative without context; reporting “Bayes risk is 2%; our classifier achieves 5%, leaving 3% excess risk” tells you how much room there is to improve.

For naive Bayes specifically, the plug-in classifier h^NB(x)=argmaxkp^(xk)π^k\hat h_{NB}(\mathbf{x}) = \arg\max_k \hat p(\mathbf{x} \mid k) \hat\pi_k approaches some asymptotic limit as nn \to \infty, but it’s not generally hh^\star because p^(xy)\hat p(\mathbf{x} \mid y) is biased (the factorization is wrong). The asymptotic NB-risk gap above Bayes risk is the bias term; the finite-nn gap above the asymptotic NB-risk is the variance term. §7 makes both terms precise for the Ng–Jordan setup.

Bayes risk on a 1D Gaussian mixture as a function of class separation. For symmetric equal-prior mixtures with σ = 1, the risk equals Φ(−Δ/2) and drops monotonically as the means move apart.
Bayes risk on a 1D Gaussian mixture as a function of class separation. For symmetric equal-prior mixtures with σ = 1, the risk equals Φ(−Δ/2) and drops monotonically as the means move apart.
Bayes risk = 0.1587. For the symmetric equal-prior case (Δ = 2.00, σ = 1.00, π = 0.5) this equals Φ(−Δ/(2σ)) = 0.1587; the displayed value is the numerical quadrature for the chosen π.

§3.3 Plug-in classifiers and the excess-risk bound

The plug-in approach builds a classifier by estimating the posterior η^(x)η(x)\hat\eta(\mathbf{x}) \approx \eta(\mathbf{x}) and thresholding at 1/21/2:

h^(x)  =  1{η^(x)>12}.\hat h(\mathbf{x}) \;=\; \mathbb{1}\bigl\{\hat\eta(\mathbf{x}) > \tfrac{1}{2}\bigr\}.

Naive Bayes, logistic regression, kernel-density-based classifiers — all are plug-in classifiers with different choices for η^\hat\eta.

Theorem (Devroye–Györfi–Lugosi 1996, Theorem 2.2; binary case). For any plug-in classifier,

R(h^)R    2EXη^(X)η(X).R(\hat h) - R^\star \;\le\; 2\,\mathbb{E}_\mathbf{X}\bigl|\hat\eta(\mathbf{X}) - \eta(\mathbf{X})\bigr|.

Proof sketch. Condition on X=x\mathbf{X} = \mathbf{x}. The Bayes classifier misclassifies with probability min(η,1η)=12(12η1)\min(\eta, 1 - \eta) = \frac{1}{2}(1 - |2\eta - 1|). The plug-in classifier misclassifies with probability that equals the Bayes classifier’s unless η^\hat\eta and η\eta lie on opposite sides of 1/21/2. In that case, the excess is 2η1|2\eta - 1|, which is bounded by 2η^η2|\hat\eta - \eta|. Taking expectations over X\mathbf{X} gives the result. The factor of 2 is loose for most distributions but tight in the worst case.

The takeaway: excess risk is bounded by twice the L1L^1 error in posterior estimation. A classifier whose η^\hat\eta is uniformly within 0.050.05 of η\eta has excess risk at most 0.10.1. Conversely, the only thing that matters for classification is getting the sign of η^1/2\hat\eta - 1/2 right at each x\mathbf{x}; absolute calibration is secondary. This is the formal version of the Domingos–Pazzani thesis we’ll meet in §3.4 and develop fully in §8: a classifier can rank classes well without estimating posterior probabilities well.

§3.4 Why NB ranks well but calibrates poorly (preview)

Naive Bayes’ estimated posterior η^NB(x)\hat\eta_{NB}(\mathbf{x}) is systematically miscalibrated whenever the conditional-independence assumption is wrong. The intuition (formalized in §8.1): when features are positively correlated given the class, the product likelihood jp^(xjy)\prod_j \hat p(x_j \mid y) multiplies redundant evidence as if it were independent, amplifying the log-likelihood and pushing the posterior toward 0 or 1.

So η^NB(x)\hat\eta_{NB}(\mathbf{x}) is typically much closer to 0 or 1 than the true η(x)\eta(\mathbf{x}) — that’s the “overconfidence” failure mode. But the sign of η^NB1/2\hat\eta_{NB} - 1/2 often matches the sign of η1/2\eta - 1/2. The plug-in classifier flips only when both posteriors lie strictly on the same side of 1/21/2 but in different positions; the sign-match is robust to monotone-distorted probability estimates. This is why a model with terrible calibration can still classify almost as well as the Bayes classifier — Domingos and Pazzani (1997) prove this rigorously for an interesting class of misspecified naive-Bayes models, and we’ll re-derive their result in §8.1.

§4. Gaussian Naive Bayes

§4.1 The per-class Gaussian conditional-density assumption

For continuous features xRd\mathbf{x} \in \mathbb{R}^d, the simplest naive-Bayes likelihood is per-class, per-coordinate Gaussian:

p(xjY=k)  =  12πσjk2exp ⁣((xjμjk)22σjk2).p(x_j \mid Y = k) \;=\; \frac{1}{\sqrt{2\pi\sigma_{jk}^2}} \exp\!\left(-\frac{(x_j - \mu_{jk})^2}{2\sigma_{jk}^2}\right).

Combined with the independence factorization, the multivariate likelihood is

p(xY=k)  =  j=1dp(xjY=k)  =  1(2π)d/2jσjkexp ⁣(12j=1d(xjμjk)2σjk2).p(\mathbf{x} \mid Y = k) \;=\; \prod_{j=1}^{d} p(x_j \mid Y = k) \;=\; \frac{1}{(2\pi)^{d/2}\prod_j \sigma_{jk}} \exp\!\left(-\frac{1}{2}\sum_{j=1}^{d}\frac{(x_j - \mu_{jk})^2}{\sigma_{jk}^2}\right).

This is a multivariate Gaussian with diagonal covariance Σk=diag(σ1k2,,σdk2)\boldsymbol\Sigma_k = \mathrm{diag}(\sigma_{1k}^2, \ldots, \sigma_{dk}^2) — features uncorrelated within each class. Per-class means μk\boldsymbol\mu_k may differ; per-class variance vectors σk2\boldsymbol\sigma_k^2 may differ. Parameter count: 2dK+(K1)2dK + (K-1), including the priors. Linear in dd, as advertised.

§4.2 MLE for μk\boldsymbol\mu_k, σk2\boldsymbol\sigma_k^2, and πk\pi_k

Given nn iid pairs (Xi,Yi)(\mathbf{X}_i, Y_i), the joint log-likelihood is

(θ)  =  i=1nlogπYi  +  i=1nj=1dlogp(XijYi;μ,σ).\ell(\boldsymbol\theta) \;=\; \sum_{i=1}^{n} \log\pi_{Y_i} \;+\; \sum_{i=1}^{n}\sum_{j=1}^{d} \log p(X_{ij} \mid Y_i; \boldsymbol\mu, \boldsymbol\sigma).

The two terms decouple — the priors πk\pi_k depend only on the class labels, and the per-feature Gaussian parameters (μjk,σjk2)(\mu_{jk}, \sigma_{jk}^2) depend only on the corresponding feature values within each class. Set nk:={i:Yi=k}n_k := |\{i : Y_i = k\}| for the per-class counts. Maximizing each term separately:

π^k  =  nkn,μ^jk  =  1nki:Yi=kXij,σ^jk2  =  1nki:Yi=k(Xijμ^jk)2.\hat\pi_k \;=\; \frac{n_k}{n}, \qquad \hat\mu_{jk} \;=\; \frac{1}{n_k}\sum_{i : Y_i = k} X_{ij}, \qquad \hat\sigma_{jk}^2 \;=\; \frac{1}{n_k}\sum_{i : Y_i = k} (X_{ij} - \hat\mu_{jk})^2.

Derivation of μ^jk\hat\mu_{jk}. The relevant piece of \ell involving μjk\mu_{jk} is i:Yi=k(Xijμjk)2/(2σjk2)-\sum_{i : Y_i = k} (X_{ij} - \mu_{jk})^2 / (2\sigma_{jk}^2). Differentiating with respect to μjk\mu_{jk} and setting to zero: i:Yi=k(Xijμjk)/σjk2=0\sum_{i : Y_i = k} (X_{ij} - \mu_{jk}) / \sigma_{jk}^2 = 0, which gives the sample mean. The same one-variable Gaussian-MLE argument as in formalstatistics’s maximum-likelihood topic.

Derivation of σ^jk2\hat\sigma_{jk}^2. The relevant piece is i:Yi=klogσjki:Yi=k(Xijμ^jk)2/(2σjk2)-\sum_{i : Y_i = k} \log\sigma_{jk} - \sum_{i : Y_i = k} (X_{ij} - \hat\mu_{jk})^2/(2\sigma_{jk}^2). Differentiating with respect to σjk2\sigma_{jk}^2: nk/(2σjk2)+(Xijμ^jk)2/(2σjk4)=0-n_k/(2\sigma_{jk}^2) + \sum (X_{ij} - \hat\mu_{jk})^2 / (2\sigma_{jk}^4) = 0, which gives the sample variance with denominator nkn_k (the MLE; the unbiased estimator uses nk1n_k - 1).

Var-smoothing safeguard. Because σ^jk2\hat\sigma_{jk}^2 can vanish if all in-class observations are identical, scikit-learn’s GaussianNB adds a small additive term ϵmaxjVar(Xj)\epsilon \cdot \max_j \mathrm{Var}(X_{\cdot j}) to every variance estimate, with default ϵ=109\epsilon = 10^{-9}. This avoids divide-by-zero in the log-density and is essentially harmless in practice.

§4.3 The decision boundary is a quadric

The Gaussian-NB log-posterior ratio between two classes kk and \ell is

logP(Y=kx)P(Y=x)  =  logπkπ  +  j=1d[12logσj2σjk2(xjμjk)22σjk2+(xjμj)22σj2].\log\frac{P(Y = k \mid \mathbf{x})}{P(Y = \ell \mid \mathbf{x})} \;=\; \log\frac{\pi_k}{\pi_\ell} \;+\; \sum_{j=1}^{d}\left[\, \frac{1}{2}\log\frac{\sigma_{j\ell}^2}{\sigma_{jk}^2} - \frac{(x_j - \mu_{jk})^2}{2\sigma_{jk}^2} + \frac{(x_j - \mu_{j\ell})^2}{2\sigma_{j\ell}^2} \,\right].

The right-hand side is a quadratic polynomial in x\mathbf{x} (the squares expand into xj2x_j^2 terms with class-dependent coefficients). Setting it to zero gives the decision boundary, which is therefore a quadric — generally an ellipse, hyperbola, or parabola in 2D; the multivariate version is a quadric hypersurface.

A useful special case: when the per-class variance vectors are equal (σjk2=σj2\sigma_{jk}^2 = \sigma_j^2 across kk), the xj2x_j^2 terms cancel and the decision boundary becomes linear. This reduces GNB to a special case of LDA — diagonal LDA — and shows that the diagonal-covariance structure is the source of the quadric (not the per-class differences in μk\boldsymbol\mu_k).

Decision boundaries for Gaussian Naive Bayes, LDA, and QDA on the same 2D anisotropic two-class fixture. GNB ignores within-class correlation; LDA forces a shared covariance; QDA fits per-class covariance.
Decision boundaries for Gaussian Naive Bayes, LDA, and QDA on the same 2D anisotropic two-class fixture. GNB ignores within-class correlation; LDA forces a shared covariance; QDA fits per-class covariance.
GNB assumes a diagonal class-covariance and ignores within-class correlations; LDA forces a single covariance across classes; QDA fits a full covariance per class. Watch how the three boundaries diverge as you change the anisotropy and rotation.

§4.4 LDA / QDA / GNB — three corners of one design space

ModelCovariance structureFree params per classDecision boundary
LDAShared Σ\boldsymbol\Sigma across classesdd (mean only)Linear
GNBPer-class diagonal Σk\boldsymbol\Sigma_k2d2dQuadric
QDAPer-class general Σk\boldsymbol\Sigma_kd+d(d+1)/2d + d(d+1)/2Quadric

All three model the within-class density as Gaussian. They differ in how much covariance structure they’re willing to estimate from data:

  • LDA estimates one d×dd \times d matrix shared across classes; ignores per-class anisotropy entirely but pools data efficiently. Best when classes have similar shapes and class separation is mainly in the mean.
  • QDA estimates a separate d×dd \times d matrix per class; captures the most structure but burns the most parameters. Best when classes differ in shape and enough data is available to fit Kd(d+1)/2K \cdot d(d+1)/2 matrices.
  • GNB estimates one diagonal matrix per class; allows per-class shapes but ignores correlation between features within each class. Always wrong on real data (features are usually correlated), but cheap to fit and surprisingly competitive at small nn — the §7 Ng–Jordan story.

In an even more degenerate corner: diagonal LDA shares a single diagonal covariance across all classes — most heavily restricted of all, linear decision boundary, often the strongest small-nn baseline for high-dimensional classification.

§4.5 Implementation: scikit-learn GaussianNB and var-smoothing

A few practical notes:

  • var_smoothing parameter. Default 10910^{-9}. Adds ϵmaxjVar(Xj)\epsilon \cdot \max_j \mathrm{Var}(X_{\cdot j}) to every variance estimate. Increase to 10710^{-7} if predictions are unstable (zero-variance features), tune via cross-validation if necessary.
  • Numerical safety. Use scipy.special.logsumexp for posterior normalization, never np.log(np.sum(np.exp(...))).
  • Partial fit. GaussianNB.partial_fit supports online learning via Welford’s running-mean / running-variance update — useful for streaming data where the entire training set doesn’t fit in memory.
  • Multi-class. All MLE formulas apply with K>2K > 2 — the only change is that the prediction is a KK-way argmax over log-posteriors.
  • Inverse-Wishart prior. A full Bayesian GNB would place an inverse-Wishart prior on each σk2\boldsymbol\sigma_k^2 vector. The posterior-mean variance is then (α+(xμ^)2)/(α+nk1)(\alpha + \sum (x - \hat\mu)^2) / (\alpha + n_k - 1) for a particular hyperparameter α\alpha — equivalent to var-smoothing for an appropriate choice. (We’ll see the analogous conjugate-update story for categorical features in §6, where the calculation is cleaner.)

§5. Multinomial and Bernoulli Naive Bayes

§5.1 Multinomial NB: the bag-of-words generative story

For text classification, the canonical feature representation is the bag of words: count how many times each vocabulary token appears in a document, ignoring word order. A document is a vector xN0V\mathbf{x} \in \mathbb{N}_0^V where VV is the vocabulary size and xjx_j is the count of token jj.

Generative model. Given a class label yy, generate the document by repeatedly sampling tokens from a categorical distribution with class-specific probabilities θy=(θy1,,θyV)\boldsymbol\theta_y = (\theta_{y1}, \ldots, \theta_{yV}) where jθyj=1\sum_j \theta_{yj} = 1. If the document has total length N(x):=jxjN(\mathbf{x}) := \sum_j x_j:

p(xy,θy)  =  N(x)!jxj!j=1Vθyjxj.p(\mathbf{x} \mid y, \boldsymbol\theta_y) \;=\; \frac{N(\mathbf{x})!}{\prod_j x_j!} \prod_{j=1}^{V} \theta_{yj}^{x_j}.

The multinomial coefficient N(x)!/xj!N(\mathbf{x})! / \prod x_j! doesn’t depend on yy — drops out of any argmax — so the relevant log-likelihood is

logp(xy)  =  j=1Vxjlogθyj  +  const.\log p(\mathbf{x} \mid y) \;=\; \sum_{j=1}^{V} x_j \log\theta_{yj} \;+\; \text{const}.

This is linear in the feature vector x\mathbf{x} with class-dependent weights logθy\log\boldsymbol\theta_y. The full log-posterior logπy+xlogθy\log\pi_y + \mathbf{x}^\top \log\boldsymbol\theta_y is the dot-product form a discriminative linear classifier would use; the difference is in how θy\boldsymbol\theta_y is estimated.

The “naive” assumption here is the within-class part: tokens within a single document are assumed iid from θy\boldsymbol\theta_y, ignoring the fact that real text has strong sequential and topic-coherence dependencies. McCallum and Nigam (1998) is the canonical reference for the Multinomial vs Bernoulli choice — the latter is the next subsection.

§5.2 MLE for token probabilities and the zero-count crisis

The MLE for θyj\theta_{yj} is the empirical token frequency within class yy:

θ^yj  =  i:Yi=yXijj=1Vi:Yi=yXij  =  cyjcy,\hat\theta_{yj} \;=\; \frac{\sum_{i : Y_i = y} X_{ij}}{\sum_{j'=1}^{V} \sum_{i : Y_i = y} X_{ij'}} \;=\; \frac{c_{yj}}{c_{y\cdot}},

where cyjc_{yj} is the total count of token jj in class yy training documents and cy:=jcyjc_{y\cdot} := \sum_j c_{yj}. Derivation: maximize ijXijlogθyj\sum_i \sum_j X_{ij} \log\theta_{yj} subject to jθyj=1\sum_j \theta_{yj} = 1 via a Lagrange multiplier λ\lambda. First-order conditions: cyj/θyj=λc_{yj}/\theta_{yj} = \lambda for all jj, so θyjcyj\theta_{yj} \propto c_{yj} and normalization gives the above.

The zero-count crisis. Suppose token jj^\star never appears in any class-yy training document, so cyj=0c_{yj^\star} = 0 and θ^yj=0\hat\theta_{yj^\star} = 0. Now a test document containing token jj^\star has logp(xy)=\log p(\mathbf{x} \mid y) = -\infty — class yy is categorically ruled out, even if the test document overwhelmingly looks like a class-yy document otherwise. This is the zero-frequency problem (Lewis 1998), and it makes raw MLE multinomial NB unusable in practice. The fix is Laplace smoothing — replace counts cyjc_{yj} with cyj+αc_{yj} + \alpha for some α>0\alpha > 0 — which we’ll derive as a conjugate-Bayesian update in §6.

Per-class token counts
pitcherinninghitteamseasonpatientdoctordrughealthclinic
baseball
medicine
Top distinctive tokens per class (highest log-likelihood-ratio against the mean):
  • baseball: pitcher, hit, inning, team, season
  • medicine: drug, patient, clinic, doctor, health
Query document token counts
Posterior P(class | doc)
baseball
1.000
medicine
0.000
The classifier predicts baseball. Try adding patient/doctor counts to flip the verdict.

§5.3 Bernoulli NB: binary-feature variant for short documents

When documents are short (single sentences, social-media posts) or the question is presence/absence rather than count, Bernoulli NB is a more natural model:

  • Features are binary: xj{0,1}x_j \in \{0, 1\} — token jj either appears in the document or not.
  • Per-class likelihood is a product of Bernoullis: p(xy)=jθyjxj(1θyj)1xjp(\mathbf{x} \mid y) = \prod_j \theta_{yj}^{x_j} (1 - \theta_{yj})^{1 - x_j}.
  • Importantly, the absence of a token is informative — the (1θyj)1xj(1 - \theta_{yj})^{1 - x_j} factor explicitly penalizes class yy when a token typical of class yy is missing. Multinomial NB, by contrast, simply gives that factor a probability of 1 (the token contributes nothing if its count is 0).

MLE: θ^yj=(i:Yi=y1{Xij>0})/ny\hat\theta_{yj} = (\sum_{i : Y_i = y} \mathbb{1}\{X_{ij} > 0\}) / n_y. Same zero-count crisis when a token never appears in some class; same Laplace smoothing fix.

When does Bernoulli win? Short documents (one or two sentences) where token presence is more informative than token count; very small vocabularies where the multinomial-coefficient correction matters less; situations where a token’s absence is diagnostically important (negation, missing keyword). McCallum and Nigam (1998) report Bernoulli NB winning on small-vocabulary subsets and Multinomial winning on full-vocabulary, longer-document benchmarks.

§5.4 Complement Naive Bayes (Rennie et al. 2003)

Rennie, Shih, Teevan, and Karger (2003) identified a systematic flaw in vanilla Multinomial NB: when class proportions are very unequal, the larger-class likelihood estimates dominate the smaller-class estimates simply because more counts are aggregated. They proposed Complement Naive Bayes, which estimates θy\boldsymbol\theta_y from the complement of class yy — all documents not belonging to class yy — and inverts the decision rule:

θ^yjCNB  =  α+i:YiyXijαV+ji:YiyXij,y^CNB(x)  =  argminyjxjlogθ^yjCNB.\hat\theta_{yj}^{\text{CNB}} \;=\; \frac{\alpha + \sum_{i : Y_i \ne y} X_{ij}}{\alpha V + \sum_{j'} \sum_{i : Y_i \ne y} X_{ij'}}, \qquad \hat y^{\text{CNB}}(\mathbf{x}) \;=\; \arg\min_{y} \sum_j x_j \log\hat\theta_{yj}^{\text{CNB}}.

The argmin (rather than argmax) implements “the class least like the data” — flipping the standard rule. Rennie et al. also add log-count weighting (log(1 + x_j) instead of raw counts) and per-document length normalization. These TF-IDF-like preprocessing steps improve Multinomial NB even without the complement trick.

Scikit-learn implements both: MultinomialNB(alpha=1.0) and ComplementNB(alpha=1.0, norm=True). The complement variant is the recommended default for text classification on imbalanced data.

§5.5 Implementation: log-sum-exp, sparse matrices, vectorized prediction

Text-classification matrices are very sparse — a vocabulary of 30,000 tokens with average document length 200 gives a density of 0.7%\approx 0.7\%. scikit-learn uses scipy.sparse.csr_matrix throughout, and the implementation of MultinomialNB.predict_log_proba is essentially one sparse matrix product:

log_posterior = X @ log_theta.T + log_class_priors

where log_theta is (K, V) and X is (n, V) sparse — total cost O(nnz(X)K)O(\text{nnz}(\mathbf{X}) \cdot K) rather than O(nVK)O(n V K). Normalization via log-sum-exp is then a single broadcast operation along the class axis.

The same trick works for Bernoulli NB; the only difference is that “presence” must be extracted from the count matrix first (X.binarize() in scikit-learn). Gaussian NB does not benefit from sparsity in the same way because the Gaussian log-density involves squared differences from the mean — a dense operation.

§6. Smoothing as conjugate Bayesian update

§6.1 Laplace add-one smoothing as a uniform Dirichlet prior

Recall the MLE zero-count crisis from §5.2: θ^yj=0\hat\theta_{yj} = 0 ruins the log-likelihood whenever an unseen token appears in a test document. The standard fix adds a fictitious pseudo-count α>0\alpha > 0 to every cell:

θ^yjLaplace  =  cyj+αcy+αV.\hat\theta_{yj}^{\text{Laplace}} \;=\; \frac{c_{yj} + \alpha}{c_{y\cdot} + \alpha V}.

When α=1\alpha = 1, this is Laplace add-one smoothing (Laplace 1812 — yes, that Laplace). When α=1/2\alpha = 1/2, Krichevsky–Trofimov smoothing. When α<1\alpha < 1, the smoothing is light; when α\alpha \to \infty, the estimate converges to the uniform 1/V1/V regardless of data.

The Bayesian interpretation: θ^yjLaplace\hat\theta_{yj}^{\text{Laplace}} is the posterior mean under a symmetric Dirichlet prior θyDirichlet(α,α,,α)\boldsymbol\theta_y \sim \mathrm{Dirichlet}(\alpha, \alpha, \ldots, \alpha). We make this precise in the next subsection.

§6.2 The Dirichlet–multinomial conjugate pair

The Dirichlet distribution over the (V1)(V-1)-simplex {θR>0V:jθj=1}\{\boldsymbol\theta \in \mathbb{R}_{>0}^V : \sum_j \theta_j = 1\} has density

Dir(θα)  =  Γ(α0)jΓ(αj)j=1Vθjαj1,α0:=jαj.\mathrm{Dir}(\boldsymbol\theta \mid \boldsymbol\alpha) \;=\; \frac{\Gamma(\alpha_0)}{\prod_j \Gamma(\alpha_j)} \prod_{j=1}^{V} \theta_j^{\alpha_j - 1}, \qquad \alpha_0 := \sum_j \alpha_j.

Conjugacy theorem. If θDir(α)\boldsymbol\theta \sim \mathrm{Dir}(\boldsymbol\alpha) and cθMultinomial(N,θ)\mathbf{c} \mid \boldsymbol\theta \sim \mathrm{Multinomial}(N, \boldsymbol\theta), then θcDir(α+c)\boldsymbol\theta \mid \mathbf{c} \sim \mathrm{Dir}(\boldsymbol\alpha + \mathbf{c}).

Proof.

Bayes’ rule: the posterior density is proportional to (prior) × (likelihood),

p(θc)    jθjαj1jθjcj  =  jθj(αj+cj)1,p(\boldsymbol\theta \mid \mathbf{c}) \;\propto\; \prod_j \theta_j^{\alpha_j - 1} \cdot \prod_j \theta_j^{c_j} \;=\; \prod_j \theta_j^{(\alpha_j + c_j) - 1},

which is the Dirichlet density up to a normalizing constant — i.e., Dir(α+c)\mathrm{Dir}(\boldsymbol\alpha + \mathbf{c}). The multinomial coefficient N!/cj!N!/\prod c_j! depends only on c\mathbf{c}, contributes to the normalizer but not the posterior shape.

Posterior mean. E[θc]=(α+c)/(α0+N)\mathbb{E}[\boldsymbol\theta \mid \mathbf{c}] = (\boldsymbol\alpha + \mathbf{c})/(\alpha_0 + N). Component-wise, E[θjc]=(αj+cj)/(α0+N)\mathbb{E}[\theta_j \mid \mathbf{c}] = (\alpha_j + c_j)/(\alpha_0 + N).

Symmetric special case. With α=(α,,α)\boldsymbol\alpha = (\alpha, \ldots, \alpha), the posterior mean is exactly the Laplace formula θ^jLaplace=(cj+α)/(c+αV)\hat\theta_j^{\text{Laplace}} = (c_j + \alpha)/(c_\cdot + \alpha V). The α=1\alpha = 1 (uniform Dirichlet) corresponds to add-one smoothing; α=1/2\alpha = 1/2 to Jeffreys’ prior (Krichevsky–Trofimov).

This is the cleanest way to think about smoothing. It’s not a heuristic regularizer — it’s the closed-form Bayesian posterior under a particular weakly-informative prior. The α\alpha parameter controls how much weight to put on the prior vs the data, and the choice of α=1\alpha = 1 (uniform) is the smallest amount of smoothing that still makes the estimator well-defined.

Counts = (3, 0, 5). The orange dashed curve traces the posterior mean as α sweeps from 10⁻² to 10². At α = 1 we get Laplace smoothing.

§6.3 Add-α\alpha smoothing and cross-validation

In practice, α\alpha is a hyperparameter and the right value depends on the dataset. Common heuristics:

  • α=1\alpha = 1 (Laplace add-one). The default in scikit-learn. Works well on medium-sized vocabularies where most tokens are observed in most classes.
  • α=0.01\alpha = 0.01 or 0.10.1 (light smoothing). For very large vocabularies and rich training data — the prior should be down-weighted relative to the data.
  • α=10\alpha = 10 or higher (heavy smoothing). For very small training sets where the empirical token frequencies are noisy.
  • Cross-validation. The principled choice. Tune α\alpha on a held-out fold to minimize log-loss or maximize accuracy.

The §6 fixture below sweeps α{0.01,0.1,1.0,10.0}\alpha \in \{0.01, 0.1, 1.0, 10.0\} on the 20-Newsgroups subset and shows the test-accuracy plateau in the middle.

Five-fold cross-validation accuracy as a function of the Laplace α on the 20-Newsgroups baseball-vs-medicine task. The selected α is the maximizer.
Five-fold cross-validation accuracy as a function of the Laplace α on the 20-Newsgroups baseball-vs-medicine task. The selected α is the maximizer.

§6.4 Posterior-predictive vs MAP

For a fully Bayesian NB, predicting a new token x~\tilde x given the training counts c\mathbf{c} uses the posterior-predictive:

P(X~=jc)  =  ΔV1θjp(θc)dθ  =  E[θjc]  =  αj+cjα0+N,P(\tilde X = j \mid \mathbf{c}) \;=\; \int_{\Delta^{V-1}} \theta_j \, p(\boldsymbol\theta \mid \mathbf{c}) \, d\boldsymbol\theta \;=\; \mathbb{E}[\theta_j \mid \mathbf{c}] \;=\; \frac{\alpha_j + c_j}{\alpha_0 + N},

which is exactly the Laplace formula. For the Dirichlet–multinomial pair, the posterior-predictive equals the posterior mean. This is a happy coincidence of the conjugacy — it doesn’t hold in general (for Gaussian–Gaussian, the posterior-predictive has wider variance than a plug-in normal at the posterior mean).

So the Laplace-smoothed plug-in classifier we’ve been using is the proper Bayesian posterior-predictive classifier — no integration over θ\boldsymbol\theta needed. This is one reason naive Bayes with Laplace smoothing is so widely used: it’s both empirically simple and theoretically defensible.

MAP vs posterior-mean. The MAP estimator is θ^yjMAP=(αj+cyj1)/(α0+cyV)\hat\theta_{yj}^{\text{MAP}} = (\alpha_j + c_{yj} - 1)/(\alpha_0 + c_{y\cdot} - V) — same as the posterior mean but with αj1\alpha_j - 1 in the numerator (the additional 1-1 comes from the Dirichlet density’s θjαj1\theta_j^{\alpha_j - 1} exponent). When αj<1\alpha_j < 1, the MAP can be negative or undefined; the posterior mean is always well-defined and gives the more standard “add-α\alpha” formula. We use posterior-mean throughout.

§6.5 Empirical Bayes choice of α\alpha

When cross-validation is too expensive (very large datasets, online learning), one can choose α\alpha by empirical Bayes — maximize the marginal likelihood p(cα)p(\mathbf{c} \mid \alpha) over α\alpha:

p(cα)  =  p(cθ)p(θα)dθ  =  Γ(αV)Γ(N+αV)jΓ(α+cj)Γ(α)p(\mathbf{c} \mid \alpha) \;=\; \int p(\mathbf{c} \mid \boldsymbol\theta) p(\boldsymbol\theta \mid \alpha) d\boldsymbol\theta \;=\; \frac{\Gamma(\alpha V)}{\Gamma(N + \alpha V)} \prod_j \frac{\Gamma(\alpha + c_j)}{\Gamma(\alpha)}

(closed form by Dirichlet–multinomial conjugacy). Maximize the log-marginal-likelihood numerically — it’s smooth and one-dimensional, so any scalar optimizer works. Minka (2000) gives fixed-point iteration formulas that are faster than gradient descent.

For typical text-classification problems, empirical Bayes and cross-validated α\alpha agree to within a factor of 2 on the optimal value. The main reason to prefer cross-validation is that it directly targets the loss you care about (accuracy, log-loss), whereas empirical Bayes targets marginal likelihood — which is a sensible proxy but not identical.

§7. The discriminative-vs-generative asymptotics

§7.1 The Ng–Jordan (2002) setup

Ng and Jordan (2002) compare a generative classifier (Gaussian NB) with its discriminative counterpart (logistic regression) on a shared model class. The setup is essentially the cleanest possible:

  • Two equiprobable classes Y{0,1}Y \in \{0, 1\}, π0=π1=1/2\pi_0 = \pi_1 = 1/2.
  • Features XRd\mathbf{X} \in \mathbb{R}^d with class-conditional Gaussian: XY=1N(μ,I)\mathbf{X} \mid Y = 1 \sim \mathcal{N}(\boldsymbol\mu, \mathbf{I}), XY=0N(μ,I)\mathbf{X} \mid Y = 0 \sim \mathcal{N}(-\boldsymbol\mu, \mathbf{I}) for some unit-norm μRd\boldsymbol\mu \in \mathbb{R}^d. Identity covariance, equal magnitudes — both the generative model (GNB with shared diagonal Σ=I\boldsymbol\Sigma = \mathbf{I}) and the discriminative model (logistic regression with linear decision boundary) are correctly specified.
  • The Bayes-optimal classifier is the linear classifier y^(x)=1{xμ>0}\hat y(\mathbf{x}) = \mathbb{1}\{\mathbf{x}^\top \boldsymbol\mu > 0\}.

GNB and logistic regression in this setup both converge to the Bayes-optimal classifier as nn \to \infty. The interesting question is how fast.

The Ng–Jordan headline result: GNB converges at rate O(log(d)/n)O(\sqrt{\log(d)/n}) while logistic regression converges at rate O(d/n)O(\sqrt{d/n}). For excess error, that’s O(logd/n)O(\log d / n) vs O(d/n)O(d / n). At small nn and large dd, GNB wins by a substantial margin; at large nn, the discriminative classifier wins because it’s asymptotically optimal in a broader sense (correctly classifies even when the Gaussian-likelihood assumption fails).

§7.2 Logistic regression’s O(d/n)O(d/n) rate

Logistic regression maximizes the conditional log-likelihood:

w^LR  =  argmaxwi=1n[yilogσ(xiw)+(1yi)log(1σ(xiw))],\hat{\mathbf{w}}_{\text{LR}} \;=\; \arg\max_{\mathbf{w}} \sum_{i=1}^{n} \bigl[\, y_i \log\sigma(\mathbf{x}_i^\top \mathbf{w}) + (1-y_i) \log(1 - \sigma(\mathbf{x}_i^\top \mathbf{w})) \,\bigr],

where σ\sigma is the sigmoid. Standard MLE asymptotics: n(w^LRw)dN(0,I1)\sqrt n (\hat{\mathbf{w}}_{\text{LR}} - \mathbf{w}^\star) \overset{d}{\to} \mathcal{N}(\mathbf{0}, \mathbf{I}^{-1}) where I\mathbf{I} is the Fisher information. For the Ng–Jordan setup, the Fisher information matrix is I(w)=E[σ(Xw)(1σ)XX]\mathbf{I}(\mathbf{w}^\star) = \mathbb{E}[\sigma(\mathbf{X}^\top \mathbf{w}^\star)(1-\sigma)\mathbf{X}\mathbf{X}^\top], which scales like Id\mathbf{I}_d at the truth. So w^LRw2=Op(d/n)\|\hat{\mathbf{w}}_{\text{LR}} - \mathbf{w}^\star\|^2 = O_p(d/n), and the excess 0/1 risk is also O(d/n)O(d/n) to leading order (the constant depends on the marginal-density gap at the decision boundary).

Sample complexity: to reach ϵ\epsilon excess error, logistic regression needs n=O(d/ϵ)n = O(d / \epsilon) samples.

§7.3 Gaussian NB’s O(log(d)/n)O(\log(d)/n) rate — the union-bound argument

Gaussian NB with shared diagonal covariance estimates the per-coordinate class means and a shared per-coordinate variance. Under the Ng–Jordan setup the variance is known to be 1, so the only parameters are μ^j+:=1n1i:yi=1xij\hat\mu_j^{+} := \frac{1}{n_1}\sum_{i:y_i=1} x_{ij} and μ^j:=1n0i:yi=0xij\hat\mu_j^{-} := \frac{1}{n_0}\sum_{i:y_i=0} x_{ij}. The classifier output reduces to the sign of x(μ^+μ^)\mathbf{x}^\top (\hat{\boldsymbol\mu}^+ - \hat{\boldsymbol\mu}^-).

The estimate error decomposes per coordinate: μ^j+μj\hat\mu_j^+ - \mu_j is Gaussian with variance 1/n12/n1/n_1 \le 2/n (since n1n/4n_1 \ge n/4 with high probability by Hoeffding). By a sub-Gaussian union bound, the max-coordinate error is

maxjdμ^j+μj  =  Op ⁣(logd/n).\max_{j \le d} |\hat\mu_j^+ - \mu_j| \;=\; O_p\!\left(\sqrt{\log d / n}\right).

This logd\sqrt{\log d} instead of d\sqrt{d} is what makes GNB’s rate dimension-light: errors at the dd coordinates are averaged (via the dot product in the decision rule), not summed in L2L^2. By Cauchy–Schwarz and the union-bound max-coordinate control, the excess 0/1 risk is O(log(d)/n)O(\log(d)/n).

Sample complexity: to reach ϵ\epsilon excess error, GNB needs n=O(logd/ϵ)n = O(\log d / \epsilon) samples.

Caveat — when this works and when it doesn’t. The Ng–Jordan rate assumes the GNB model is correctly specified (true class-conditional is Gaussian with the assumed covariance structure). On real data the assumption is wrong, and GNB inherits a model-misspecification bias term that does not vanish with nn. The O(logd/n)O(\log d / n) rate refers only to the variance term; the asymptotic gap to the Bayes risk is the bias term. So at large nn, logistic regression beats GNB because the misspecification bias dominates the variance — that’s the “crossover.”

§7.4 The crossover phenomenon — empirical verification

We run the Ng–Jordan §3 simulation: vary nn from 20 to 5000, fix d=100d = 100 (a regime where logd4.6\log d \approx 4.6 is much smaller than dd), and plot test error for Gaussian NB and unregularized logistic regression across 15 replicates per sample size. The two rates predict that GNB approaches its asymptotic error faster than logistic regression — its learning curve should be steeper at small-to-moderate nn while logistic regression catches up only once n/dn / d is large.

That’s what the empirical curve shows. Between n=80n = 80 and n=320n = 320 — the sweet spot where the logd/n\log d / n rate is favorable but d/nd / n is still pessimistic — GNB pulls ahead by about five percentage points (test error ≈ 0.22 vs ≈ 0.27 at n=320n = 320). Both methods converge to the Bayes-error floor near 0.170.17 once n1000n \gtrsim 1000.

At very small nn (here n=20n = 20 to 4040), logistic regression edges out GNB by a thin margin. The theoretical asymptotics don’t pin down constants, and at sample sizes barely larger than the feature count, the precise behavior depends on which estimator’s per-coordinate variance bites first. The clean “NB wins at small nn” story emerges most clearly at higher dd — toggle the viz to d=200d = 200 to see the small-nn GNB-wins region widen substantially, exactly as the rate inequality predicts.

Test-error learning curves for Gaussian NB and unregularized logistic regression on the Ng–Jordan synthetic setup at d = 100. GNB approaches the Bayes floor faster between n ≈ 80 and n ≈ 320; both converge near n = 2560.
Test-error learning curves for Gaussian NB and unregularized logistic regression on the Ng–Jordan synthetic setup at d = 100. GNB approaches the Bayes floor faster between n ≈ 80 and n ≈ 320; both converge near n = 2560.
Feature dimension d:loading...
Loading Ng–Jordan sweep...

§7.5 Caveats: misspecification, regularization, and “no free lunch”

Three caveats on the §7.4 verification.

Correct specification matters. The simulation is GNB-optimal: features are independent given the class, true covariance is I\mathbf{I}. On real data the model is misspecified and GNB’s asymptotic bias may dominate the small-nn variance advantage entirely. The Ng–Jordan paper itself reports mixed results on UCI datasets — GNB sometimes wins, sometimes loses, with no clean rate-prediction.

Regularization changes the story. 2\ell_2-regularized logistic regression effectively reduces dd via shrinkage, narrowing the gap to GNB at small nn. 1\ell_1-regularized logistic (the lasso from high-dimensional-regression §11.1) is even more competitive: sample complexity becomes O(slogd/n)O(s \log d / n) where ss is the true sparsity, matching GNB’s dimension-light rate when s=O(logd)s = O(\log d). So the §7.4 GNB-wins region narrows when both methods are tuned via cross-validation.

No free lunch. Generative classifiers win when their generative model is approximately right. When it’s badly wrong, they lose. There’s no universal classifier — the right answer depends on what you know about the data-generating process.

§8. Calibration and class-probability estimation

§8.1 Why naive Bayes is miscalibrated

A classifier is calibrated if, among the test examples for which it predicts P^(Y=1x)=p\hat P(Y = 1 \mid \mathbf{x}) = p, the fraction with Y=1Y = 1 is approximately pp. NB is rarely calibrated — its predicted probabilities cluster near 0 and 1 while the true posterior takes intermediate values for most inputs. The phenomenon is called overconfidence.

The mechanism (Domingos–Pazzani 1997): the conditional-independence assumption multiplies log-likelihoods that aren’t really independent, so correlated evidence is counted multiple times. Suppose two features X1,X2X_1, X_2 are perfectly correlated within each class — the second feature carries no new information beyond the first — but NB treats them as independent. NB’s log-likelihood ratio includes the same evidence twice, doubling its magnitude. Posteriors are pushed twice as far from 1/21/2 as they should be: a true posterior of 0.70.7 becomes an NB-estimated posterior of 0.91\approx 0.91.

But the sign of the log-likelihood ratio is preserved. Overconfidence doesn’t flip classifications; it just exaggerates them. That’s why NB classifies well (rank-preserving) but calibrates poorly (magnitude-distorted). Theorem 3 of Domingos and Pazzani (1997) makes this precise for a class of correlated-feature NB models.

Predicted P(Y = 1 | x) from Multinomial NB on the 20-Newsgroups test split. Probabilities pile up at 0 and 1 — the characteristic NB overconfidence.
Predicted P(Y = 1 | x) from Multinomial NB on the 20-Newsgroups test split. Probabilities pile up at 0 and 1 — the characteristic NB overconfidence.

§8.2 Platt scaling — fit a sigmoid on the scores

Platt (1999) proposed fitting a one-dimensional logistic regression on the raw classifier scores to recover calibration:

P^Platt(Y=1x)  =  σ(As(x)+B),\hat P_{\text{Platt}}(Y = 1 \mid \mathbf{x}) \;=\; \sigma(A \cdot s(\mathbf{x}) + B),

where s(x)s(\mathbf{x}) is the raw classifier output (for NB, the log-posterior-odds), and A,BA, B are fit by MLE on a held-out calibration set (never the training set!). Two parameters only, so the fit is robust to small calibration sets.

When to use Platt scaling: classifier scores are already monotone in the true posterior (NB satisfies this in practice) and the transformation is approximately sigmoid-shaped. Works well for SVMs and naive Bayes in the “moderate-sample-but-overconfident” regime.

Critical detail. The held-out set must be separate from both training and final testing. Fitting Platt on the training set and evaluating on the same set produces in-sample-perfect calibration that’s meaningless out-of-sample. The recipe: split data 50/50 into train/calibration, fit the classifier on train, fit Platt on calibration. Re-split if data is precious.

§8.3 Isotonic regression — nonparametric monotone fit

Zadrozny and Elkan (2002) proposed isotonic regression as a nonparametric alternative to Platt scaling. The idea: fit a monotone-nondecreasing function gg that minimizes i(yig(si))2\sum_i (y_i - g(s_i))^2 over g{monotone nondecreasing}g \in \{\text{monotone nondecreasing}\}.

Closed-form solution via the pool-adjacent-violators (PAV) algorithm: walk through the sorted-by-score data, replacing any violation g(si)>g(si+1)g(s_i) > g(s_{i+1}) with their average, repeat until monotone. O(n)O(n) time, no hyperparameters.

When isotonic wins over Platt: large held-out sets (PAV becomes a smooth nonparametric estimator), or when the score-to-posterior map is not approximately sigmoid. When Platt wins: small held-out sets (isotonic overfits the calibration set when ncalibn_{\text{calib}} is small).

The §8.3 fixture compares both on the 20-Newsgroups task — see the next code cell.

Reliability diagrams for raw NB, Platt-scaled, and isotonic-regressed probabilities on the 20-Newsgroups task. Platt brings the calibration curve closest to the diagonal.
Reliability diagrams for raw NB, Platt-scaled, and isotonic-regressed probabilities on the 20-Newsgroups task. Platt brings the calibration curve closest to the diagonal.
Loading calibration data...

§8.4 Calibration metrics: Brier, log-loss, ECE

Three standard metrics for evaluating calibration quality.

Brier score. Mean squared error between predicted probability and binary label:

Brier  =  1ni=1n(piyi)2.\text{Brier} \;=\; \frac{1}{n} \sum_{i=1}^{n} (p_i - y_i)^2.

Decomposes (Murphy 1973) into reliability + resolution − uncertainty: low Brier requires both calibration and discrimination. Range [0,1][0, 1], lower is better.

Log-loss (cross-entropy). 1ni[yilogpi+(1yi)log(1pi)]-\frac{1}{n}\sum_i [y_i \log p_i + (1-y_i)\log(1-p_i)]. Strictly proper scoring rule — only minimized when pi=P(Y=1xi)p_i = P(Y = 1 \mid \mathbf{x}_i) exactly. Penalizes overconfident wrong predictions much more harshly than Brier (logarithmic vs quadratic blow-up near p=0p = 0 or p=1p = 1).

Expected Calibration Error (ECE). Bin predictions into KK bins, compare per-bin mean predicted probability to per-bin frequency of positives:

ECE  =  k=1KBknpBkyBk.\text{ECE} \;=\; \sum_{k=1}^{K} \frac{|B_k|}{n} \bigl| \overline{p}_{B_k} - \overline{y}_{B_k} \bigr|.

Hand-tunable via KK; sensitive to binning strategy. Guo et al. (2017) recommend ECE for reporting calibration on classification tasks.

Which loss for which task? Use log-loss to train (it’s the proper-scoring-rule MLE); use Brier or ECE to report (more interpretable). For ranking-only tasks (search relevance, anomaly detection) where calibration doesn’t matter, AUC is the right metric instead.

§9. Beyond strict independence: structure-learning extensions

§9.1 Tree-Augmented Naive Bayes (TAN) via Chow–Liu

The simplest principled relaxation of the strict-independence assumption: allow each feature XjX_j to have one additional parent in the DAG (besides YY). The resulting graph is a tree over the features rooted at YY. The joint factorizes as

p(y,x)  =  p(y)j=1dp(xjy,xπ(j)),p(y, \mathbf{x}) \;=\; p(y) \prod_{j=1}^{d} p(x_j \mid y, x_{\pi(j)}),

where π(j)\pi(j) is the feature-parent of XjX_j (or \emptyset for the tree root).

How do you pick the tree? Chow and Liu (1968) — twenty years before Friedman–Geiger–Goldszmidt 1997 brought it to classification — proved that the maximum-likelihood tree is the maximum-mutual-information spanning tree of the complete weighted graph on the features. Edge weights are conditional mutual informations I(Xi;XjY)I(X_i; X_j \mid Y), computed from the training data. Run Kruskal’s or Prim’s algorithm. O(d2)O(d^2) to compute MIs, O(d2logd)O(d^2 \log d) for the MST. Choose any feature as the root; the choice doesn’t affect classification accuracy (the joint factorization is the same).

Why TAN often beats NB. TAN captures the dominant feature dependencies (those with the largest pairwise MI), reducing the “double-counting redundant evidence” failure mode of strict NB. On most UCI benchmarks, TAN classifies better than NB and produces better-calibrated probabilities, at the cost of KdV2K \cdot d \cdot V^2 parameters (vs KdVK \cdot d \cdot V for NB).

Dashed gray = NB's assumed independence (Y → X_i only). Solid orange = the Chow–Liu tree (edge thickness ∝ pairwise MI). Planted dependencies: X_0–X_1 and X_2–X_3 with probability 0.80; the tree should recover these as high-MI edges.

§9.2 Averaged One-Dependence Estimators (AODE)

Webb, Boughton, and Wang (2005) proposed AODE as an ensemble alternative to TAN. Instead of picking one spanning tree, AODE averages over all dd classifiers that have each single feature XjX_j as a “super-parent” (every other feature depends on XjX_j and on YY).

P^AODE(yx)    j=1d1{ny,xjm}P^(y,xj)ijP^(xiy,xj),\hat P_{\text{AODE}}(y \mid \mathbf{x}) \;\propto\; \sum_{j=1}^{d} \mathbb{1}\{n_{y, x_j} \ge m\} \cdot \hat P(y, x_j) \prod_{i \ne j} \hat P(x_i \mid y, x_j),

where mm (often 30) is a frequency threshold to avoid unreliable conditional estimates.

Advantages over TAN. No structure search (deterministic ensemble), more robust against any single dependency choice being wrong, often beats TAN on benchmarks. Disadvantage. Storage: Kd2V2K \cdot d^2 \cdot V^2 parameters — substantial at large vocabulary. Suitable for moderate-feature-count tabular tasks; not ideal for text.

Other Bayesian-network extensions. Selective NB (Langley & Sage 1994) selects a feature subset before fitting. K-dependence Bayesian classifier (Sahami 1996) generalizes TAN to up to KK parents per feature. Hidden NB (Jiang–Zhang–Cai 2009) introduces a latent hidden parent. All sit on the spectrum between NB and the full joint, trading parameters for expressiveness.

§9.3 Hidden Naive Bayes

Jiang, Zhang, and Cai (2009) introduced Hidden Naive Bayes (HNB) as another structural extension: each feature XjX_j depends on YY and on a hidden parent Xhp(j)X_{hp(j)} that is a weighted combination of all other features. The weights are computed from mutual information; the hidden-parent effect aggregates structure across all features rather than picking just one.

HNB’s joint is

P(y,x)  =  P(y)j=1dP(xjy,xhp(j)),P(y, \mathbf{x}) \;=\; P(y) \prod_{j=1}^{d} P(x_j \mid y, x_{hp(j)}),

where P(xjy,xhp(j))=ijWjiP(xjy,xi)P(x_j \mid y, x_{hp(j)}) = \sum_{i \ne j} W_{ji} P(x_j \mid y, x_i) and WjiW_{ji} is the normalized conditional mutual information I(Xj;XiY)I(X_j; X_i \mid Y).

Reported results: HNB beats NB and is competitive with TAN/AODE while being computationally cheaper than AODE (no V2V^2 count tables). Practical use is more limited than TAN, but for low-to-moderate dimensional tabular classification it’s another option.

§9.4 Connection to latent Dirichlet allocation

The Multinomial NB story — one θy\boldsymbol\theta_y per class, documents drawn from the corresponding multinomial — is a special case of Latent Dirichlet Allocation (LDA, Blei–Ng–Jordan 2003). LDA extends NB by allowing each document to be a mixture of class-like “topics” rather than belonging to a single class:

LDA: ϕdDir(α),znCat(ϕd),wnCat(βzn).\text{LDA: }\quad \boldsymbol\phi_d \sim \mathrm{Dir}(\alpha), \quad z_n \sim \mathrm{Cat}(\boldsymbol\phi_d), \quad w_n \sim \mathrm{Cat}(\boldsymbol\beta_{z_n}).

Each document dd has a topic distribution ϕd\boldsymbol\phi_d, each word wnw_n in the document is drawn from a topic-specific vocabulary distribution βzn\boldsymbol\beta_{z_n}. NB recovers as the special case where each document’s topic distribution is a one-hot vector (i.e., the class label).

Why this matters for NB. It positions NB as the simplest, most degenerate member of a much larger family of latent-variable text models — LDA, hierarchical Dirichlet processes, dynamic topic models. Each adds structural flexibility (mixed topics, topic-document correlations, time evolution) at the cost of harder inference (variational methods, MCMC). NB is the limit case where the latent variable degenerates to an observed class label and inference becomes one MLE.

§9.5 Naive Bayes in the broader graphical-models family

The structural progression — NB, TAN, AODE, full Bayesian network — sits at one end of a spectrum that the graphical-models topic on formalstatistics (when shipped) will treat in full generality:

  • Naive Bayes = star graph rooted at YY (this topic, §1–§8).
  • TAN = tree over features rooted at YY (this topic, §9.1).
  • AODE = ensemble of star-graphs with each feature as a super-parent (this topic, §9.2).
  • General Bayesian network classifier = arbitrary DAG with YY as a vertex.
  • Latent Dirichlet allocation = NB lifted to mixture-of-multinomials with latent topics (§9.4).
  • Markov random fields / conditional random fields = undirected analogs; CRF is the discriminative undirected counterpart to MRF.

Naive Bayes is the limit of simplicity on this spectrum. Many tasks that look like they need more structure turn out to be fine with NB; many that look amenable to NB turn out to need more structure. The diagnostic question is “do feature dependencies, after conditioning on YY, materially affect classification?” — if yes, move to TAN or beyond; if no, NB is plenty.

§10. Connections, applications, and limits

§10.1 Text classification as the canonical success story

Wang and Manning (2012) revisited naive Bayes vs SVMs vs logistic regression on a battery of text-classification tasks (sentiment, topic, news categorization). They found that a properly tuned Multinomial NB (with log-count features and bigram extension) is competitive with or beats much more complex methods on most benchmarks, especially with limited training data.

Their preferred variant — NB-SVM — combines NB log-likelihood-ratio features with an SVM linear classifier, getting the best of both: NB’s small-nn advantage and SVM’s large-nn asymptotic optimality. On 10 of 11 benchmark datasets, NB-SVM beats every published baseline through 2012 — including ones with elaborate feature engineering.

The Wang–Manning takeaway: for text classification, start with NB before reaching for anything more complex. It’s fast, it’s interpretable, it’s competitive, and any model you reach for next should beat NB on a held-out test set before being worth the additional complexity.

§10.2 The ranking-vs-calibration thesis

Domingos and Pazzani’s 1997 paper had a more general thesis than just “NB works on text” — they argued that classifiers that estimate posterior probabilities poorly can still rank classes correctly, and many real-world classification tasks need only the ranking. Hand (2006) develops this further: most “improvements” in classifier accuracy reported in the ML literature are within the noise of the within-classifier variance from random data splits.

For tasks where ranking is what matters (search relevance, anomaly scores, top-K prediction), NB is competitive with much more complex methods. For tasks where calibrated probabilities matter (medical risk scores, financial forecasts, downstream Bayesian updates), NB’s overconfidence is a real liability — fix it with Platt scaling or isotonic regression (§8), or use a discriminative method.

The §3.3 plug-in excess-risk bound formalizes this: classification accuracy is sensitive to the sign of η^1/2\hat\eta - 1/2 at each x\mathbf{x}, not to the magnitude. NB’s miscalibration mostly preserves signs (overconfidence in the same direction as truth), hence the ranking-vs-calibration separation.

§10.3 Where naive Bayes breaks down

Three failure modes worth flagging.

Strongly correlated features. Duplicate or near-duplicate features amplify NB’s overconfidence (§8.1) and can cause the sign of the log-likelihood ratio to be wrong, not just the magnitude. Mitigations: TAN/AODE structure (§9), feature selection (Yang–Pedersen 1997) to remove redundancy, or simply switch to logistic regression.

Calibrated-probability requirements. Medical risk scores, financial probabilities, anything fed into a downstream Bayesian update — NB’s raw probabilities are not trustworthy. Always Platt-scale or isotonic-regress on a held-out set, or use a discriminative method with proper-loss training (cross-entropy).

Long-range dependencies. Text classification with token-order-sensitive structure (sentiment of “not good”), images with spatial structure, time series — NB’s bag-of-features representation ignores order. Use sequence models (RNN, Transformer), structured-output models (CRF), or convolutional architectures instead. NB is for the bag-of-features regime; outside it, it’s not the right tool.

Gaussian NB
Accuracy = 0.858
ECE = 0.1170
Brier = 0.1312
Logistic regression
Accuracy = 0.842
ECE = 0.0934
Brier = 0.1098
At high ρ, NB treats the 8 duplicate features as 8 independent votes, multiplying its evidence — predicted probabilities collapse to 0 / 1 and ECE balloons. LR pools the duplicates into a single effective coefficient.

§10.4 Forward pointers in formalML

NB connects forward to several formalML topics.

  • conformal-prediction (T4) — NB is a natural base classifier for split-conformal classification. Compute raw NB class-probability scores, calibrate on a held-out set via quantile-thresholding, output a prediction set with marginal coverage. The §8 calibration framework developed here is what makes NB suitable: raw NB probabilities are too overconfident to be conformal scores directly, but Platt-scaled or isotonic-regressed scores work well. See conformal-prediction §3.6 for the implementation.
  • bayesian-neural-networks (T5) — At the other end of the generative-classifier spectrum from NB. BNNs treat the network weights as random variables with priors; the classifier output is a posterior over class labels rather than a point estimate. NB is the simplest generative classifier (one weight per feature per class); BNNs are the most complex (millions of weights with Bayesian posteriors). The §7 generative-vs-discriminative trade-offs apply throughout.
  • high-dimensional-regression (T2 sibling) — The §7 discriminative-vs-generative comparison maps onto §11.1’s logistic-lasso vs NB comparison. When sparsity is the dominant structure, sparse logistic regression beats NB. When the small-nn regime dominates, NB beats sparse logistic regression. The crossover depends on dd, nn, ss, and the true generative structure.
  • prediction-intervals (T4) — Calibrated NB probabilities give natural Bayesian prediction intervals on the per-class probability scale. See prediction-intervals §4 for the construction.

§10.5 Closing thesis

Naive Bayes endures, despite being theoretically suspect, because it occupies a specific niche extremely well: the small-nn, large-dd, ranking-dominated regime. In that niche, the dimension-light sample complexity (O(logd/n)O(\log d / n)) dominates the misspecification bias, the ranking-preserving nature of overconfidence preserves classification quality, and the simple log-linear structure makes training and prediction fast enough to deploy at any scale.

Outside that niche — when nn is large enough for discriminative methods to converge, when calibrated probabilities are required for downstream decisions, when feature dependencies dominate the classification signal — naive Bayes is the wrong tool. But the right answer is rarely to ignore it. The Wang–Manning advice is reasonable: always start with NB and compare to it. A more complex method that doesn’t beat NB on a held-out set is not worth its additional cost.

The mathematical interest of NB extends beyond practical engineering. It’s the simplest member of a much richer family — directed graphical models — and the cleanest setting in which to develop the generative-vs-discriminative classifier theory that pervades modern ML. The §7 Ng–Jordan asymptotic comparison applies, with modifications, to any pair of generative + discriminative classifiers fit on the same hypothesis class. The §8 calibration framework applies to any miscalibrated classifier, not just NB. The §3 plug-in excess-risk bound is the canonical formalization of “good ranking with bad calibration.” Naive Bayes is a 60-year-old method, and its pedagogical value remains as strong as ever.

Connections and Further Reading

Internal formalML topics this builds on:

  • concentration-inequalities — direct prerequisite for the §7 union-bound rate proofs.
  • kl-divergence and shannon-entropy — drive the §9.1 Chow–Liu mutual-information construction.
  • pac-learning — rigorous sample-complexity vocabulary for §7.
  • high-dimensional-regression — §7 comparison with logistic regression (§11.1 sparse logistic).

Internal formalML topics this informs:

  • conformal-prediction — calibrated NB scores feed split-conformal classification.
  • bayesian-neural-networks — the deep generative-classifier extension of NB.
  • prediction-intervals — Bayesian NB posterior-predictive gives natural class-probability intervals.

Sister-site links (cross-site frontmatter):

  • formalstatistics/discrete-distributions — Bernoulli / Multinomial / Categorical foundations for §5.
  • formalstatistics/bayesian-foundations-and-prior-selection — Dirichlet–multinomial conjugacy for §6.
  • formalstatistics/maximum-likelihood — MLE machinery for §§4–5.
  • formalstatistics/exponential-families — the log-linear structure of §2.2.
  • formalstatistics/multivariate-distributions — multivariate Gaussian background for §4.
  • formalcalculus/multiple-integrals — Dirichlet simplex and Gaussian integrals.
  • formalcalculus/derivative — MLE first-order conditions.

External references appear in the brief and the MDX frontmatter. The foundational triad to read first: Domingos & Pazzani (1997) for the why-NB-works-despite-being-wrong analysis, Ng & Jordan (2002) for the discriminative-vs-generative asymptotic comparison, McCallum & Nigam (1998) for the canonical Multinomial-vs-Bernoulli study on text. For a contemporary survey: Murphy (2012) Chapter 3 (NB as the simplest probabilistic classifier) and Chapter 4 (the Gaussian-NB / LDA / QDA family).

Connections

  • Direct prerequisite for the §7.3 GNB asymptotic-error bound. The Ng–Jordan O(log d / n) sample complexity proof uses a union bound over d Gaussian MLE deviations together with sub-Gaussian concentration; the high-dimensional-regression-style maximal inequality machinery is the substrate. Cross-link via Markdown, do not re-derive. concentration-inequalities
  • The §9.1 Chow–Liu tree-augmented naive Bayes construction selects the tree that minimizes KL divergence between the true joint and the product-of-pairwise-marginals approximation — equivalently, the maximum-mutual-information spanning tree. The §10.2 'ranking-vs-calibration' discussion also invokes KL divergence between true and NB-estimated posteriors. kl-divergence
  • Mutual information drives the §9.1 Chow–Liu edge selection. The §3.2 Bayes-risk decomposition also leans on the Shannon-entropy framing of the class-label uncertainty: H(Y) - H(Y | X) is the maximum information any classifier can extract. shannon-entropy
  • The §7 Ng–Jordan asymptotic comparison is fundamentally a sample-complexity statement: how many examples does each classifier need to reach error ε of its asymptotic-best? The PAC-learning framework (VC dimension, growth function, Rademacher complexity) provides the rigorous machinery for this kind of comparison; the §7 brief uses PAC concepts and forward-points to the pac-learning topic for the rigorous foundations. pac-learning
  • The §7 discriminative-vs-generative comparison contrasts Gaussian NB (generative) with logistic regression (discriminative); the high-dim-regression topic develops the §11.1 logistic lasso as the high-dimensional discriminative classifier. The §10.3 correlated-features failure mode echoes high-dim-regression's §6.2 irrepresentable-condition discussion. NB is the small-n generative alternative when sparsity assumptions in high-dim-regression don't hold. high-dimensional-regression
  • NB is a natural base classifier for split-conformal classification: produce class-probability scores, calibrate by quantile-thresholding on a held-out set, output a prediction set with marginal coverage. The §8 calibration framework developed here is what makes NB suitable as a conformal base classifier (raw NB probabilities are typically too overconfident). conformal-prediction
  • NB is the simplest generative classifier in the same hierarchy that BNNs occupy at the deep end. The §10.4 forward pointer relates NB's Dirichlet–multinomial conjugacy to the prior-over-weights stance BNNs take, and the §10.3 correlated-features failure of NB is exactly the kind of problem BNNs were designed to handle through richer parameterizations. bayesian-neural-networks

References & Further Reading