Bayes' theorem

Updating belief with evidence — the foundation of probabilistic ML

Why

Bayes' theorem is arguably the most important single equation in ML. It tells you how to rationally update your beliefs when you get new evidence. Naive Bayes, Bayesian optimisation (used in AutoML and hyperparameter tuning), variational inference, and MAP estimation are all direct applications.

Intuition

Before seeing any evidence, you have a prior belief — your best guess before the data arrives. Then you observe something (evidence). Bayes' theorem tells you how to update your prior into a posterior — your new, refined belief after incorporating the evidence.

The update is multiplicative: you scale your prior by how likely the evidence is under each hypothesis, then renormalise. Hypotheses that predict the evidence well get their probability boosted; those that predict it poorly get shrunk.

Explanation
The formula
P(E|H) · P(H) P(H|E) = —————————— P(E) where: H = hypothesis (what we want to know) E = evidence (what we observed) P(H) = prior: belief in H BEFORE seeing E P(E|H) = likelihood: how probable is E if H were true P(E) = evidence: total probability of E (normalisation constant) P(H|E) = posterior: updated belief in H AFTER seeing E
Concrete example — spam detection
H = "email is spam" E = "email contains the word 'win'" P(spam) = 0.01 (1% of all emails are spam — prior) P("win"|spam) = 0.80 (80% of spam emails contain "win" — likelihood) P("win") = 0.05 (5% of all emails contain "win" — evidence) P(spam|"win") = (0.80 × 0.01) / 0.05 = 0.008 / 0.05 = 0.16 Seeing "win" updates spam probability from 1% → 16%. The word is suspicious but not conclusive — more features needed.
Naive Bayes classifier — Bayes in action

Naive Bayes classifies by computing the posterior of each class given all features. The "naive" assumption: all features are independent given the class — which simplifies the product enormously:

P(class|f₁,f₂,...,fₙ) ∝ P(class) × P(f₁|class) × P(f₂|class) × ... × P(fₙ|class) In log space (to avoid underflow with many features): log P(class|features) ∝ log P(class) + Σ log P(fᴵ|class) Prediction: argmax over classes of the above expression.

Despite the independence assumption being almost always wrong, Naive Bayes works surprisingly well for text — because even with wrong probabilities, the ranking of classes is often correct.