Math & Statistics

Bayes’ Theorem

The mathematical recipe for updating beliefs given evidence — and why intuition fails on rare events.

🟢 beginner4 min readprobabilitybayesian
Bayes’ Theorem updates a prior probability P(A) into a posterior P(A|B) upon observing evidence B: P(A|B) = P(B|A)P(A) / P(B). In machine learning, it underpins Naive Bayes, MAP estimation, Bayesian optimization, and VAEs. The key interview insight is base-rate neglect: when prior probability is low, even a test with 99% accuracy yields more false positives than true positives.

The formula and its components

Bayes' Theorem decomposes conditional probability into four distinct terms:

P(A | B) = [ P(B | A) · P(A) ] / P(B)

Posterior = [ Likelihood · Prior ] / Evidence

Base rate fallacy: Why human intuition fails

When testing for rare events (fraud, rare disease, network intrusions), the prior base rate P(A) dominates the posterior calculation.

MetricValueMeaning
Base Rate P(Disease)0.1% (1 in 1000)Rare prior event
Sensitivity P(+ | Disease)99%Low false negatives
Specificity P(- | No Disease)99%Low false positive rate (1%)

For 100,000 tested individuals:

Posterior P(Disease | +) = 99 / (99 + 999) ≈ 9.0%. Even with 99% test accuracy, 91% of positive results are false alarms because the prior is so small.

Where Bayes appears in ML rounds

  1. Naive Bayes Classifiers: Assumes feature independence given class: P(Y|X) ∝ P(Y) ∏ P(X_i|Y). Fast baseline for NLP and spam filtering.
  2. MAP vs MLE: MAP adds a prior term to parameter estimation argmax_θ P(X|θ)P(θ). Adding a Gaussian prior over weights is mathematically equivalent to L2 regularization (Ridge).
  3. Bayesian Optimization: Fits a Gaussian Process prior over an expensive objective function (hyperparameter search) to balance exploration and exploitation via acquisition functions (Expected Improvement, UCB).

Say this out loud

"Bayes’ Theorem updates prior beliefs with new evidence. In real-world systems, ignoring the base rate leads to massive overconfidence — a 99% accurate test on a 0.1% rare event still yields ~91% false positives. In ML, Bayes connects regularization to priors: MAP estimation with a Gaussian prior is equivalent to L2 regularization, while a Laplacian prior gives L1."

Follow-ups to expect

Check yourself

Question 1 of 3

A disease affects 1 in 1,000 people. A test is 99% accurate (99% sensitivity, 99% specificity). If a random person tests positive, the probability they actually have the disease is closest to

More in Math & Statistics

See all →
Central Limit Theorem4 minLaw of Large Numbers4 minExpectation & Variance4 min