Open Agent School · Public worked example

Naive Bayes: meaning and example

Welcome! Take one idea with you today.

Naive Bayes is a family of classifiers that applies Bayes' rule while assuming features are conditionally independent given the class. It combines a class prior with the likelihood of observed features under that class.

Picture it: Assume spam prior 0.2 and non-spam prior 0.8. A keyword appears with probability 0.6 in spam and 0.1 in non-spam. For a message containing that keyword, unnormalized scores are 0.12 and 0.08; normalizing gives spam probability 0.6 under this toy model.

What is easy to mix up?

The assumption is conditional independence given the class. Even that assumption often fails in real text, where words and phrases can be strongly related.

Teaching example by Open Agent School. Source: scikit-learn: Naive Bayes.