Machine Learning · Chapter 16 of 40

Naive Bayes

NAIVE BAYES applies Bayes' theorem assuming features are INDEPENDENT — 'naive' because they usually aren't.

Surprisingly effective for text classification (spam, sentiment).

Example 1 (python)
from sklearn.naive_bayes import MultinomialNB
m = MultinomialNB().fit(X_train, y_train)
print(m.score(X_test, y_test))
Output
0.87

Very fast to train.

Example 2 (python)
# GaussianNB for continuous, MultinomialNB for counts, BernoulliNB for binary

Pick the variant to match your data.

Key points

  • Based on Bayes' theorem.
  • Assumes feature independence.
  • Very fast to train.
  • Great baseline for text.
💡 Note: Multinomial Naive Bayes on TF-IDF features is a strong, cheap baseline for spam and sentiment tasks.

📝 Quick Quiz

1. Naive Bayes assumes features are:

2. It is popular for:

3. For word counts you use: