Sub topic 15
Limitations, and why naive Bayes still works
This chapter assumes you know the naive Bayes decision rule, how smoothing works, and how to train a model in scikit-learn. It covers where the independence assumption breaks and why accuracy often survives anyway.
What the assumption gets wrong
Naive Bayes scores a class as the prior times a product of per-feature likelihoods. That product is only correct if features are independent given the class. Real features rarely are.
In text, "new" and "york" appear together far more often than their separate frequencies predict. Naive Bayes treats them as two separate pieces of evidence and counts the evidence twice.
Common failure modes
- Double counting. Correlated features push the score in the same direction more than once, so the model becomes overconfident.
- Extreme probabilities.
predict_probaoften returns values near 0 or 1, even on examples the model gets wrong. - Unseen combinations. The model cannot learn that two words together mean something different from each word alone.
- Zero-frequency features. Without smoothing, one unseen word sets a class score to zero. Laplace smoothing fixes this.
- Wrong distribution. Gaussian naive Bayes on skewed or multimodal features fits poorly, because the per-class bell curve does not match the data.
Why it still works
Classification only needs the correct class to have the highest score. It does not need accurate probabilities.
Suppose duplicated evidence inflates every class's score. If it inflates the true class at least as much as the others, the ranking does not change. The argmax stays the same while the probabilities become distorted.
Three other factors help:
- Low variance. The model has few parameters, one per feature per class. It overfits less than a model that learns feature interactions, especially with small training sets.
- High-dimensional sparse data. In text, most features are weakly informative and the dependencies are spread thin. Errors tend to cancel out.
- Strong dependencies in both directions. When the dependencies between features are similar across classes, they affect the class scores about equally.
You can see the effect in a small experiment. Duplicating a feature column breaks independence completely, yet the predicted class often stays the same while the probability grows.
import numpy as np
from sklearn.naive_bayes import GaussianNB
rng = np.random.default_rng(0)
X = np.vstack([rng.normal(0, 1, (50, 1)), rng.normal(1, 1, (50, 1))])
y = np.array([0] * 50 + [1] * 50)
x_new = np.array([[0.8]])
for copies in (1, 5):
Xc = np.hstack([X] * copies)
model = GaussianNB().fit(Xc, y)
xc = np.hstack([x_new] * copies)
print(copies, model.predict(xc), model.predict_proba(xc).round(3))With five copies, the model treats one measurement as five independent ones. The probability for the predicted class moves toward 1. The predicted label is the same, because the log-likelihood ratio is scaled by the number of copies and keeps its sign.
Decision criteria
Use naive Bayes when you need a fast baseline, have little data, or have very many sparse features. Prefer a model that can represent interactions, such as logistic regression or gradient boosting, when features are strongly dependent and you have enough data. Calibrate the outputs whenever you use the probabilities for thresholds or cost-sensitive decisions.
Exercise
You duplicate every feature column in a naive Bayes training set. Will predicted labels or predicted probabilities change more, and why?
Show answer
Probabilities change more. Each duplicated feature adds its log-likelihood term a second time, so the gap between class scores grows and probabilities move toward 0 and 1. Labels change only when the doubled evidence reverses the ranking, which happens rarely when the original evidence already pointed to one class.