Bayes' Theorem
Prerequisites
- Probability Basics
- Conditional Probability — P(A|B), multiplication rule
🎯 Learning Objectives
- State and derive Bayes' theorem
- Identify prior, likelihood, posterior, and evidence
- Apply the law of total probability to compute the denominator
- Solve 5+ worked examples including GATE previous year problems
1. Bayes' Formula
Bayes' Theorem
Where:
- P(H) — Prior probability of hypothesis H
- P(E|H) — Likelihood of evidence E given H
- P(H|E) — Posterior probability of H given E
- P(E) — Evidence (marginal likelihood), computed via total probability
Intuition
Bayes' theorem lets us update our belief about a hypothesis after observing new evidence. The prior captures what we believed before; the posterior captures what we believe after.
2. Law of Total Probability
Law of Total Probability
If H1, H2, …, Hn are mutually exclusive and exhaustive:
This is how we compute the denominator in Bayes' theorem when P(E) is not given directly.
3. Worked Examples
Example 1 — Medical Diagnosis Classic GATE
A disease affects 1% of the population. A test has 99% sensitivity (true positive rate) and 95% specificity (true negative rate). If a person tests positive, what is P(disease)?
Solution:
- P(D) = 0.01, P(Dc) = 0.99
- P(+|D) = 0.99, P(+|Dc) = 1 − 0.95 = 0.05
P(+) = P(+|D)P(D) + P(+|Dc)P(Dc) = 0.99 × 0.01 + 0.05 × 0.99 = 0.0099 + 0.0495 = 0.0594
P(D|+) = (0.99 × 0.01) / 0.0594 = 0.0099 / 0.0594 = 0.1667 ≈ 16.67%
Insight: Even with a highly accurate test, if the disease is rare, most positive results are false positives! This is the base rate fallacy.
Example 2 — Spam Filter
60% of emails are spam. The word "free" appears in 80% of spam and 10% of non-spam. P(spam | "free" appears)?
Solution:
P(S) = 0.6, P(Sc) = 0.4, P(F|S) = 0.8, P(F|Sc) = 0.1
P(F) = 0.8 × 0.6 + 0.1 × 0.4 = 0.48 + 0.04 = 0.52
P(S|F) = (0.8 × 0.6) / 0.52 = 0.48 / 0.52 = 12/13 ≈ 0.923
Example 3 — Three Factories GATE 2017
Factory A produces 50% of items, B produces 30%, C produces 20%. Defective rates: A = 2%, B = 3%, C = 5%. An item is found defective. P(from factory A)?
Solution:
P(D) = 0.02(0.5) + 0.03(0.3) + 0.05(0.2) = 0.01 + 0.009 + 0.01 = 0.029
P(A|D) = (0.02 × 0.5) / 0.029 = 0.01 / 0.029 = 10/29 ≈ 0.3448
Example 4 — Two Coins GATE Style
A fair coin and a biased coin (P(H) = 0.75) are in a bag. One coin is chosen at random and tossed twice, showing HH. P(biased coin was chosen)?
Solution:
P(Fair) = P(Biased) = 0.5
P(HH|Fair) = 0.52 = 0.25
P(HH|Biased) = 0.752 = 0.5625
P(HH) = 0.25(0.5) + 0.5625(0.5) = 0.125 + 0.28125 = 0.40625
P(Biased|HH) = 0.28125 / 0.40625 = 9/13 ≈ 0.6923
Example 5 — Box Problem GATE 2020
Box 1 has 4 red and 6 blue balls. Box 2 has 7 red and 3 blue. A box is chosen with equal probability, and a ball drawn is red. P(Box 1)?
Solution:
P(R|B1) = 4/10 = 0.4, P(R|B2) = 7/10 = 0.7
P(R) = 0.4(0.5) + 0.7(0.5) = 0.2 + 0.35 = 0.55
P(B1|R) = (0.4 × 0.5) / 0.55 = 0.2 / 0.55 = 4/11 ≈ 0.3636
Example 6 — Sequential Update Advanced
A coin is either fair (H1) or double-headed (H2), equally likely. We observe Head on the first toss. What is the posterior? Now we observe Head again. Update.
After 1st Head:
P(H1|H) = [0.5 × 0.5] / [0.5 × 0.5 + 1 × 0.5] = 0.25 / 0.75 = 1/3
P(H2|H) = 2/3
After 2nd Head (use posterior from step 1 as new prior):
P(H1|HH) = [0.5 × 1/3] / [0.5 × 1/3 + 1 × 2/3] = (1/6) / (5/6) = 1/5
P(H2|HH) = 4/5
4. GATE Problem-Solving Tips
Common Mistakes to Avoid
- Confusing P(A|B) with P(B|A): Always identify which is the prior and which is the likelihood carefully.
- Forgetting the denominator: P(E) must be computed via total probability in most problems.
- Base rate neglect: A high sensitivity does NOT mean a high posterior if the prior is very low.
- Not checking if hypotheses are exhaustive: Ensure all cases are covered.
Summary
- Bayes' theorem: P(H|E) = P(E|H)P(H) / P(E)
- Total probability: P(E) = ∑ P(E|Hi)P(Hi)
- The posterior is proportional to the likelihood times the prior
- Bayes' theorem enables belief updating — the foundation of Bayesian reasoning in AI
- Expect 1-2 Bayes' theorem questions in GATE DA every year