A new message contains a word your spam class has never seen and a word your "not spam" class has never seen either. Raw maximum likelihood has an answer for that — and it's a silent, catastrophic zero.
| label | words |
|---|---|
| spam | win, urgent |
| spam | win |
| spam | urgent |
| not spam | link |
| not spam | link, win |
| not spam | (none) |
| P(word present | class) | spam | not spam |
|---|---|---|
| win | 0.667 | 0.333 |
| urgent (in message) | 0.667 | 0.000 |
| link (in message) | 0.000 | 0.667 |
Toggle to MLE: two cells sit at exactly , in red — words that never once appeared with that class in training. Toggle to MAP: the smoothing pulls every estimate off the boundary, exactly where MLE broke.
Naive Bayes classifies a message by combining a class prior with a per-word likelihood, assuming word presence is conditionally independent given the class:
- — the class prior, estimated as the fraction of training messages with that label.
- — the likelihood that word 's presence/absence matches the label, estimated from training counts.
Raw (MLE) word likelihoods are just counts: . Laplace smoothing reframes this as a MAP estimate under a Beta prior on each word:
- — the smoothing strength (here ): imagined extra present and extra absent examples.
- A single zero collapses the whole product
Naive Bayes multiplies likelihoods across every vocab word. One factor of exactly makes the entire class likelihood — no matter how strongly every other word points the other way.
- Two zero classes means an undefined posterior
If every class's likelihood hits zero for a given message, Bayes' rule divides by — the classifier has no answer at all, not even a bad one.
- Smoothing is exactly the MAP fix from the last two chapters
Add- smoothing isn't a separate trick; it's the MAP estimate from the MLE/MAP chapters applied once per word, with a prior that assumes every word is plausible in every class until proven otherwise.
| P(word present | class) | spam | not spam |
|---|---|---|
| win | 0.600 | 0.400 |
| urgent (in message) | 0.600 | 0.200 |
| link (in message) | 0.200 | 0.600 |
message = [urgent, link]
prior: P(spam)=0.50, P(not spam)=0.50
P(message | spam)=0.0480, P(message | not spam)=0.0720
Under MLE, the message [urgent, link] earns a likelihood of exactly under both classes — the classifier is stuck. Switch to MAP and a full, normalized posterior appears, because smoothing kept every likelihood strictly between and .
Vocabulary: win, urgent, link. New message: [urgent, link] — "win" is absent.
- MLE likelihoods hit zero on both sides
"urgent" never appeared in a "not spam" message (); "link" never appeared in a "spam" message (). Both class likelihoods for this message come out to exactly — MLE cannot classify it.
- MAP smooths every word likelihood off the boundary
With :
- "urgent": ,
- "link": ,
- "win" (absent): under spam, under not spam
- Multiply through and apply Bayes' rule
With equal priors ( each): unnormalized scores and , summing to . Normalizing:
Predicted label: not spam — by a clean split, computed entirely from exact fractions.
Using MAP (Laplace-smoothed) likelihoods, what is P(spam | [urgent, link])?
| P(word present | class) | spam | not spam |
|---|---|---|
| win | 0.600 | 0.400 |
| urgent (in message) | 0.600 | 0.200 |
| link (in message) | 0.200 | 0.600 |
This is the whole pipeline the course has been building toward: a prior, a likelihood built one MAP estimate at a time, and Bayes' rule to combine them — the same three ingredients behind spam filters, anomaly detectors, and any classifier that needs to say "here's my probability," not just "here's my guess."