RightSignal
1 of 4

Your RightSignal

Concept of the day1 / 3

Naive Bayes classifier

The concept

How your inbox spots spam it has never seen before

A Naive Bayes classifier guesses a category, like spam or not spam, by asking how likely each word is in each category. It learns these word odds by counting words in emails people already marked.

Say "prize" shows up in 20% of spam but only 1% of normal mail, and "meeting" in 1% of spam but 10% of normal mail. An email containing both gets a score for each category, and the bigger score wins.

It is called naive because it pretends words appear independently of each other once you know the category. That is false, but it makes the maths simple and still works well.

What it’s forScores how likely an email is to belong to a category, given the words in it.

P(c | w₁…wₙ) ∝ P(c) · Π P(wᵢ | c)

c
a category, such as spam or not spam
P(c)
the prior: how common that category is overall, e.g. 0.5
P(wᵢ | c)
how often word wᵢ appears in emails of that category
Π
multiply the word probabilities together

What it givesA score per category; divide each by their sum to get probabilities, and pick the largest.

  1. Spam: 0.5 × 0.2 × 0.01 = 0.001
  2. Not spam: 0.5 × 0.01 × 0.1 = 0.0005
  3. P(spam) = 0.001 ÷ 0.0015 ≈ 0.67