The classifier behind early spam filters. It starts from a prior belief, lets every clue (every word) nudge that belief up or down, and treats each clue as independent, which is naive, but surprisingly effective.
We want P(spam | words). Bayes’ rule flips it into things we can count: P(spam) × P(words | spam). Computing P(words | spam) for a whole combination of words is impossible, so Naive Bayes assumes each word is independent given the class and simply multiplies single-word probabilities. This page uses Bernoulli Naive Bayes: every word in the vocabulary is a yes/no feature. A word that is in the email contributes P(word | class). A word that is not in the email contributes 1 − P(word | class). Do this for both classes and compare.
Only the ratio matters, so the two scores are normalised to sum to 100%. Multiplying many small numbers underflows, so real software adds logarithms instead. That is exactly what the coloured bars show: each word, present or absent, adds or subtracts log-odds. Leaving absent words out would give a different (and wrong) answer. For example, a completely empty email is not simply “the prior”: not seeing any spammy words is itself evidence for normal mail.
“Training” is just counting, in 40 spam and 60 normal emails, how many contain each word. Words in your email are highlighted. Notice the zeros: “winner” never appeared in a normal email and “project” never in spam. With α = 0 a zero probability multiplies everything to zero and one unseen word vetoes the whole decision.
For each class, a word is either present or absent in an email: two outcomes. Laplace smoothing adds α imaginary emails to each outcome. So if a word appears in c of N emails in a class, it is treated as appearing in c + α and missing from (N − c) + α emails, out of N + 2α in total:
The 2α in the denominator is not arbitrary: it is what makes the two probabilities add up to exactly 1. This is the formula for Bernoulli Naive Bayes. Multinomial Naive Bayes (which counts how many times each word occurs) uses a different one: (word count + α) ÷ (total words in class + α·V), where V is the vocabulary size. Here is the calculation for the first word you selected:
For measurements like height or income, Naive Bayes describes each class with a bell curve per feature (a mean and a spread). Each class becomes an axis-aligned ellipse. Drag the white star to see the maths for any point, or click empty space to add points.
Raise Feature link above so x₁ and x₂ move together inside each class, with the classes separated along that same direction. The model still multiplies the two likelihoods as if they were separate evidence, so it counts the same clue twice. Accuracy barely changes, but its confidence soars past its real accuracy. Naive Bayes is often a good classifier but a poor source of trustworthy probabilities.
Training is counting and prediction is a few multiplications. It scales to huge data.
It needs few examples per class because it estimates simple one-feature statistics.
Spam filtering, topic tagging and sentiment started here and still make strong baselines.
The independence shortcut makes the probabilities overconfident. Trust the ranking more than the number.
A friendly email with one never-seen word, and no smoothing. One word overrules everything.
Same spammy words, but spam is only 5% of mail. The prior fights back.
Make the two features move together and watch confidence outrun accuracy.