Laplace Smoothing for Naive Bayes
A tiny fix that adds pretend pseudo-counts to a Naive Bayes classifier's probability estimates so that a category never seen in training doesn't instantly zero out an entire prediction.
Prerequisites: Naive Bayes Classifiers
A Naive Bayes classifier estimates the probability of each feature value given each class straight from training-data frequencies — for instance, "of all spam emails in training, what fraction contained the word 'refinance'." The trouble is multiplicative: Naive Bayes combines these per-feature probabilities by multiplying them together, and if even one feature value never appeared in training for a given class, its estimated probability is exactly zero, which zeroes out the entire product regardless of how strongly every other feature points the other way.
Laplace smoothing (also called additive smoothing) fixes this by pretending you've seen every possible feature value one extra time (or some other small constant, ) beyond what training data actually showed, before computing frequencies. Concretely, instead of estimating , you compute . This guarantees every probability estimate is strictly positive — a brand-new word never seen in spam training gets a small but nonzero probability instead of an instant, unwarranted veto over the whole prediction.
The smoothing constant is itself a tuning choice: (plain Laplace smoothing) is the common default, but larger pulls every estimate further toward a uniform distribution, which helps more when training data is sparse and hurts more when it's abundant enough that the raw frequencies are already reliable.
Laplace smoothing adds a small pseudo-count to every feature-class frequency before estimating probabilities, preventing a single unseen feature value from forcing a Naive Bayes prediction's entire probability product to zero — the smoothing strength trades bias toward uniformity for protection against sparse-data zero estimates.
Related concepts
Practice in interviews
Further reading
- Manning, Raghavan & Schutze, Introduction to Information Retrieval, ch. 13