Bernoulli Naive Bayes
Naive Bayes for yes/no features, such as whether a word appears.
The idea
Each feature is binary (present or absent). The model estimates the probability that each feature is present in each class and, unlike the multinomial version, it explicitly penalises the absence of a feature that is usually present.
P(x | c) = Π pᵢ^xᵢ (1 − pᵢ)^(1−xᵢ)
Watch it run
This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.
- spam
- not spam
A message arrives containing three words. Is it spam? Start with the prior: before reading, spam and not-spam are equally likely.
- prior:
- 50%
Word frequencies come from a tiny training set of 6 spam and 6 normal messages, with add-one smoothing.
Step by step
- 1Binarise the features.
- 2Estimate P(feature present | class) with smoothing.
- 3For a new item multiply p for present features and (1 − p) for absent ones.
- 4Pick the highest-scoring class.
Where it is used
Short texts and binary indicator data.
Watch out for
Counts carry information that is lost by binarising.