A multinomial naive Bayes spam filter uses the vocabulary . Training: spam documents "win win cash" and "cash cash"; ham documents "meeting win" and "meeting meeting cash". Using Laplace (add-one) smoothing, classify the new document "win meeting meeting". Why is the smoothing needed?
Supervised learning, Naive Bayes
Level L2 Elementary. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can estimate word probabilities from counts with smoothing and compare class scores.
Key idea
and the score is , one factor per word occurrence.
Steps
- Priors: 2 spam and 2 ham documents, so .
- Word counts. Spam: win 2, cash 3, meeting 0 (total ). Ham: win 1, cash 1, meeting 3 (total ). The vocabulary size is .
- Smoothed spam probabilities (denominator ): win , cash , meeting . Ham: win , cash , meeting .
- Scores for "win meeting meeting": spam score is , and ham score is .
- Ham wins. The posterior of ham is .
- Smoothing is needed because "meeting" never occurs in spam. Without it and the spam score would be exactly 0 for any document containing "meeting", however spammy its other words are.
Common mistakes
- Using the word count in the denominator as the number of documents rather than the total number of words in the class.
- Adding 1 to the numerator but forgetting in the denominator, so the probabilities do not sum to 1.
- Counting each distinct word once. Multinomial naive Bayes uses one factor per occurrence ("meeting" twice here); counting presence only is the Bernoulli model.
How long your answer should be
Half a page; 4–5 minutes.
Read this
Previous in Supervised learning: The training points are red, red, blue, blue and blue. Using Euclidean distance, classify the query with , and . What does this tell you about the choice of ?
Next in Supervised learning: Four observations are . What is the estimated density at using (a) a box kernel of width , that is for with , and (b) a Gaussian kernel with ?