Quant Memo
Core

Naive Bayes Classifiers

Naive Bayes turns Bayes' rule into a classifier by making one convenient, usually wrong, assumption — that every feature is independent of every other given the class — and it works surprisingly well anyway.

Prerequisites: Bayes' Theorem

You want to classify something — spam or not spam, fraud or not fraud — using several pieces of evidence at once. Bayes' rule tells you exactly how to combine evidence with a prior belief, but it needs the joint probability of seeing all that evidence together given each class, and with even a dozen features, estimating a full joint distribution from limited data is hopeless. Naive Bayes escapes this by making a bold simplification and living with the consequences.

The analogy: a doctor reading symptoms one at a time

A doctor suspects a patient has one of two conditions and observes several symptoms: fever, cough, fatigue. The fully correct approach would account for how these symptoms interact — fever and cough often occur together, and their combination carries different information than either alone. Naive Bayes is the doctor who instead asks, one symptom at a time, "given condition A, how likely is a fever? How likely is a cough? How likely is fatigue?" — and just multiplies those separate likelihoods together, pretending the symptoms never influence each other. It's a shortcut, not the truth, but it turns an intractable estimation problem into three easy ones.

The maths, one piece at a time

Bayes' rule says the probability of class CC given features x1,,xkx_1, \dots, x_k is proportional to the prior probability of CC times the probability of seeing those features under CC:

P(Cx1,,xk)P(C)P(x1,,xkC)P(C \mid x_1, \dots, x_k) \propto P(C) \, P(x_1, \dots, x_k \mid C)

P(C)P(C) is how common the class is before seeing any evidence — the base rate. P(x1,,xkC)P(x_1,\dots,x_k \mid C) is the hard part: the joint likelihood of every feature together, given the class. The naive assumption replaces that joint likelihood with a product of separate, one-feature likelihoods:

P(x1,,xkC)j=1kP(xjC)P(x_1, \dots, x_k \mid C) \approx \prod_{j=1}^{k} P(x_j \mid C)

In words: instead of asking "how likely is this whole combination of symptoms," ask "how likely is each symptom on its own," and multiply the answers. That is the entire "naive" part of the name — treating features as independent given the class, which is rarely exactly true (a cough and a fever really do move together) but is often close enough to be useful.

Worked example 1: spam filtering by hand

Two classes: spam (P(spam)=0.4P(\text{spam}) = 0.4) and not-spam (P(ham)=0.6P(\text{ham}) = 0.6). An email contains the words "free" and "winner." From training data: P(freespam)=0.6P(\text{free}\mid\text{spam}) = 0.6, P(winnerspam)=0.5P(\text{winner}\mid\text{spam}) = 0.5; P(freeham)=0.1P(\text{free}\mid\text{ham}) = 0.1, P(winnerham)=0.05P(\text{winner}\mid\text{ham}) = 0.05.

Spam score: 0.4×0.6×0.5=0.120.4 \times 0.6 \times 0.5 = 0.12. Ham score: 0.6×0.1×0.05=0.0030.6 \times 0.1 \times 0.05 = 0.003. Normalise by dividing each by their sum, 0.1230.123: P(spamemail)=0.12/0.1230.976P(\text{spam}\mid\text{email}) = 0.12/0.123 \approx 0.976. Despite ignoring any interaction between "free" and "winner" appearing together, the classifier is overwhelmingly confident this is spam — and it usually would be right.

Worked example 2: a numeric feature and Gaussian Naive Bayes

For continuous features like trade size, replace the lookup table with a Gaussian per class. Suppose "legitimate" trades have mean size $500 and standard deviation $100, and "fraudulent" trades have mean $5,000 and standard deviation $2,000. A new trade of $4,000 arrives. Using the normal density formula for each class (roughly, how many standard deviations away and how tall the bell curve is there), $4,000 is 17.5 standard deviations from the legitimate mean — essentially zero density — but only 0.5 standard deviations from the fraud mean, where the density is high. Even before weighting by priors, the likelihood ratio overwhelmingly favours fraud, illustrating how Naive Bayes handles numeric features: fit a simple distribution per class per feature, then multiply.

Distribution · normal
-2.000.002.00μvalue →
Within ±1σ 68.3%mean μ 0.00std σ 1.00

Picture two of these bell curves overlaid, one centred near $500 and a wider one centred near $5,000 — a new point's classification comes from which curve it sits under with higher density, which is exactly the mechanism in worked example 2.

Decision boundary
flexibility 3.0points on wrong side 9reasonable

Naive Bayes with Gaussian features draws boundaries that are curved but constrained by the independence assumption — drag the explorer above to compare how a flexible boundary differs from the more rigid shapes Naive Bayes is capable of.

Naive Bayes multiplies separate, per-feature likelihoods instead of estimating one hard joint likelihood. The independence assumption is almost always false, but the ranking of classes it produces is often right even when the exact probabilities are miscalibrated.

What this means in practice

Naive Bayes is fast, needs little data per parameter, and is a strong baseline for text classification, spam detection, and quick fraud triage where features are numerous and roughly informative on their own. It struggles when features are strongly correlated in a way that matters — two nearly-identical features get double-counted, since the model has no mechanism to notice they're saying the same thing twice.

The classic trap is treating Naive Bayes's output probabilities as well-calibrated. Because the independence assumption is violated, correlated features get multiplied in as if they were independent evidence, which pushes predicted probabilities toward 0 or 1 more aggressively than is justified. The ranking of classes is usually still reliable even when the exact probability isn't — don't report "98% confident" from a naive model without checking calibration first.

Related concepts

Practice in interviews

Further reading

  • Hastie, Tibshirani & Friedman, The Elements of Statistical Learning, ch. 6.6
  • Murphy, Machine Learning: A Probabilistic Perspective, ch. 3
ShareTwitterLinkedIn