A spam filter uses two yes/no features: = “contains the word offer” and = “contains a link”. The training set has 10 emails: 4 spam and 6 ham (not spam). Among spam, in 3 emails and in 3. Among ham, in 1 email and in 2. Using Bernoulli naive Bayes, how is a new email with classified (a) with maximum-likelihood estimates and (b) with Laplace (add-one) smoothing, and what is the posterior in each case?
Supervised learning, Naive Bayes
Level L2 Elementary. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can apply naive Bayes by hand, turn the scores into a posterior probability, and apply Laplace smoothing correctly.
Key idea
Naive Bayes assumes the features are independent once the class is known, so , where is the class and the -th feature. Laplace smoothing for a yes/no feature adds 1 to each count: , where is the number of class- emails with and is the number of class- emails.
Steps
- Priors are the class frequencies: for spam and for ham.
- (a) Maximum-likelihood estimates are plain fractions of counts: and ; and .
- Multiply each prior by its likelihoods. Spam: . Ham: . These are only proportional to the posteriors, so divide by their sum: . Predict spam.
- (b) Laplace smoothing adds 1 to each count and 2 to each total; it is 2 because the feature has two possible values. So , , and .
- New scores: spam ; ham . So . Predict ham.
- Comment on the flip. With only 10 emails the counts are tiny, so smoothing changes the decision. Its main job is to stop one zero count from making the whole product zero.
Common mistakes
- Adding 1 to the numerator but forgetting to add 2 (the number of values the feature can take) to the denominator.
- Leaving out the absent feature. In Bernoulli naive Bayes, still contributes the factor .
- Reporting the unnormalised products as probabilities.
How long your answer should be
Half a page of arithmetic; about 4 minutes.
Last checked on 4 December 2026.
Read this
Previous in Supervised learning: A logistic regression model gives , with , and . (a) What is the decision boundary for threshold 0.5? (b) What is it for threshold 0.8? (c) How is the point classified under each threshold?
Next in Supervised learning: A node holds 16 samples, 8 positive and 8 negative. Split sends 6 samples (5 positive, 1 negative) left and 10 samples (3 positive, 7 negative) right. Split sends 8 samples (6 positive, 2 negative) left and 8 samples (2 positive, 6 negative) right. What is the information gain (using base-2 entropy) of each split, and which split is chosen?