Bayes' Theorem in Plain Language
Learners will work through a concrete medical-test example to build intuition for prior, likelihood, and posterior probabilities without heavy math.
What Is Bayes' Theorem?
Bayes' theorem is a mathematical rule for updating beliefs in light of new evidence. It answers the question: Given that I observed X, how probable is hypothesis H? The formula is: P(H|X) = P(X|H) * P(H) / P(X). In plain English: the posterior probability of H given X equals the likelihood of observing X if H were true, times the prior probability of H, divided by the overall probability of observing X. Bayes' theorem is fundamental to machine learning, statistics, and rational reasoning under uncertainty.
# Bayes' theorem components:
# P(H|X) = Posterior -- What we want to know
# 'Probability of H given we observed X'
# P(X|H) = Likelihood -- How likely is X if H is true?
# P(H) = Prior -- Our belief in H before seeing X
# P(X) = Evidence -- Overall probability of observing X
# Rearranged:
# Posterior = (Likelihood * Prior) / Evidence
print('Posterior = (Likelihood * Prior) / Evidence')A Medical Test Example
Let's build intuition with a classic example. A rare disease affects 1% of the population. A test is 95% accurate: if you have the disease, it tests positive 95% of the time; if you don't, it tests negative 95% of the time (5% false positive rate). If you test positive, what is the probability you actually have the disease? Most people's intuition says 95%, but Bayes' theorem reveals the answer is much lower — because the disease is so rare, most positives are actually false positives.
# Medical test: Bayes' theorem applied
P_disease = 0.01 # Prior: 1% have the disease
P_no_disease = 0.99 # 99% are healthy
P_pos_given_disease = 0.95 # True positive rate (sensitivity)
P_pos_given_no_disease = 0.05 # False positive rate
# P(positive) = total probability of a positive test
P_positive = (P_pos_given_disease * P_disease +
P_pos_given_no_disease * P_no_disease)
# Bayes: P(disease | positive)
P_disease_given_pos = (P_pos_given_disease * P_disease) / P_positive
print(f'P(disease | positive test) = {P_disease_given_pos:.2%}')
# Only ~16%! Not 95% -- the low prior dominates