Naive Bayes
Classifies with Bayes' rule, assuming features are independent given the class.
The idea
For each class it multiplies the prior probability by the probability of each observed feature given that class. The "naive" independence assumption is rarely true, yet the ranking of classes is often still right. It trains in one pass and works well with little data.
P(c | x) ∝ P(c) · Π P(xᵢ | c)
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
- 1Count how often each class occurs (priors).
- 2Estimate P(feature | class) from the training data.
- 3For a new item multiply the prior by each feature's likelihood.
- 4Pick the class with the largest product.
Where it is used
Spam filtering, document classification, quick baselines.
Watch out for
Probability estimates are poorly calibrated; a zero count needs smoothing.