Interview Q&A / Machine Learning

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What is Laplace smoothing in Naive Bayes, and why is it needed?

SHORT ANSWER

If a word never appeared with a class in training, its probability is zero and wipes out the whole product. Laplace smoothing adds 1 to every word count so no probability is exactly zero.

Explain it simply

A judge who has never seen a particular excuse before declares "impossible, this person is innocent forever" because the probability is zero. Smoothing is the judge saying "I have not seen it yet, but I will not rule it out".

Example

Suppose spam emails in training contain 100 word tokens in total and the vocabulary has 50 distinct words. The word "scholarship" appears 0 times in spam.

text
Without smoothing: P(scholarship | spam) = 0 / 100 = 0
  -> any email with "scholarship" gets spam score 0, whatever else it says

With Laplace (alpha = 1):
  P(scholarship | spam) = (0 + 1) / (100 + 50) = 1/150 = 0.0067

A word seen 10 times:
  P = (10 + 1) / (100 + 50) = 11/150 = 0.0733

The denominator adds the vocabulary size so the probabilities still sum to 1.

python
from sklearn.naive_bayes import MultinomialNB
MultinomialNB(alpha=1.0)   # alpha = 1 is Laplace smoothing

Smaller alpha (such as 0.1) trusts the training counts more; larger alpha pushes probabilities toward uniform. Tune alpha by cross-validation.

What to say in the interview

"Without smoothing, one unseen word makes a class probability zero and cancels all other evidence. Laplace smoothing adds a pseudo-count of 1 to each word and the vocabulary size to the denominator. In scikit-learn it is the alpha parameter, which I tune."

Common mistakes

  • Forgetting to add the vocabulary size to the denominator.
  • Setting alpha to 0 and then seeing zero-probability errors.

#naive-bayes#laplace-smoothing#zero-frequency

Related questions

Practise more Machine Learning questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Machine Learning quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.