Skip to content
StackDecode
AI & ML Atlas
Machine LearningalgorithmInteractive simulation

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.

freemoneymeetingspam50%not spam50%
  • 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%
1/5

Word frequencies come from a tiny training set of 6 spam and 6 normal messages, with add-one smoothing.

Step by step

  1. 1Binarise the features.
  2. 2Estimate P(feature present | class) with smoothing.
  3. 3For a new item multiply p for present features and (1 − p) for absent ones.
  4. 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.

Related