1.3.3Probability & Statistics

Bayes' theorem and applications

2,188 words10 min readdifficulty · medium

What is Bayes' Theorem?

WHY does this formula work? Let's derive it from scratch.

Derivation from First Principles

Start with the definition of conditional probability: P(AB)=P(AB)P(B)P(A|B) = \frac{P(A \cap B)}{P(B)}

WHY? This says: "probability of AA given BB" = "both happen together" divided by "how often BB happens". If BB is rare, seeing AA and BB together is relatively more significant.

Similarly, we can write: P(BA)=P(AB)P(A)P(B|A) = \frac{P(A \cap B)}{P(A)}

Rearrange this second equation: P(AB)=P(BA)P(A)P(A \cap B) = P(B|A) \cdot P(A)

WHY? We're expressing the joint probability in terms of "how likely is BB if we know AA" times "how likely is AA in the first place".

Substitute into the first equation: P(AB)=P(BA)P(A)P(B)P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)}

This is Bayes' theorem. It's just algebra on conditional probability definitions. The beauty: it reverses conditioning. If you know P(BA)P(B|A) but want P(AB)P(A|B), Bayes gives you the swap.

Expanding the Denominator

Often P(B)P(B) isn't directly known. Use the law of total probability: P(B)=P(BA)P(A)+P(B¬A)P(¬A)P(B) = P(B|A) \cdot P(A) + P(B|\neg A) \cdot P(\neg A)

WHY? Event BB can happen in two mutually exclusive scenarios: when AA is true or when AA is false. Sum the weighted probabilities.

So Bayes becomes: P(AB)=P(BA)P(A)P(BA)P(A)+P(B¬A)P(¬A)P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B|A) \cdot P(A) + P(B|\neg A) \cdot P(\neg A)}

This form is most useful in practice because you can compute the posterior from likelihoods and priors alone.

Figure — Bayes' theorem and applications

Worked Examples


Why Bayes is Powerful in AI/ML

  1. Probabilistic reasoning: Handles uncertainty explicitly (vs deterministic rules)
  2. Incorporates prior knowledge: If you know disease is rare, prior P(D)P(D) is low → harder to confirm
  3. Updates incrementally: See more evidence? Apply Bayes again with the old posterior as the new prior
  4. Foundation for algorithms: Naive Bayes,esian networks, spam filters, medical AI A/B testing

Common Mistakes


Connections

  • 1.3.01-Conditional-probability-and-independence – Bayes is built on conditional probability
  • 1.3.02-Law-of-total-probability – Used to expand P(B)P(B) in the denominator
  • 2.1.05-Naive-Bayes-classifier – Direct ML application
  • 4.2.03-Bayesian-inference – Philosophical framework for updating beliefs
  • 3.4.01-Maximum-likelihood-estimation – Frequentist alternative; MLE ignores priors
  • 1.3.04-Random-variables-and-distributions – Bayes extends to continuous distributions (Bayesian updating)

Recall Explain to a 12-Year-Old

Imagine you're a detective. Someone stole cookies, and you find chocolate crumbs. Your suspects: your brother (who loves chocolate, steals cookies 80% of the time when he's around) and your dog (who eats anything, but only20% chance he'd leave crumbs).

Before seeing the crumbs, you thought your brother was around 40% of the time (that's your prior). The crumbs are evidence. Your brother would definitely leave chocolate crumbs if he stole them (high likelihood). The dog might, but less often.

Bayes' theorem is the math that tells you: "Okay, you saw chocolate crumbs. Given that, what's the NEW chance it was your brother?" It combines your starting guess with how well each suspect explains the crumbs. The one who's more likely to create that evidence gets a bigger update. That's Bayes!


#flashcards/ai-ml

What is the formula for Bayes' theorem? :: P(AB)=P(BA)P(A)P(B)P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)} where P(AB)P(A|B) is posterior, P(BA)P(B|A) is likelihood, P(A)P(A) is prior, P(B)P(B) is evidence.

What are the four components of Bayes' theorem? :: Posterior P(AB)P(A|B), Likelihood P(BA)P(B|A), Prior P(A)P(A), Evidence/Marginal Likelihood P(B)P(B).

Why is the denominator in Bayes' theorem necessary?
It normalizes the posterior probability so that all posteriors sum to 1 and prevents probabilities from exceeding 1.
How do you expand P(B)P(B) when it's not directly known?
Use the law of total probability: P(B)=P(BA)P(A)+P(B¬A)P(¬A)P(B) = P(B|A) \cdot P(A) + P(B|\neg A) \cdot P(\neg A).
In the medical test example, why is the posterior probability only 16% despite95% test accuracy?
Because the disease is rare (1% prior). The false positives from the large healthy population (99% × 5% = 4.95%) outnumber the true positives (1% × 95% = 0.95%).
What does "naive" mean in Naive Bayes classifier?
It assumes features are conditionally independent given the class, which is usually false but simplifies computation and often works well in practice.
What is the difference between P(AB)P(A|B) and P(BA)P(B|A)?
P(AB)P(A|B) is the probability of AA given BB occurred (posterior), while P(BA)P(B|A) is the probability of BB given AA occurred (likelihood). They are generally not equal.
How does Bayes' theorem handle multiple hypotheses?
P(AiB)=P(BAi)P(Ai)j=1nP(BAj)P(Aj)P(A_i|B) = \frac{P(B|A_i) \cdot P(A_i)}{\sum_{j=1}^n P(B|A_j) \cdot P(A_j)} where hypotheses AiA_i are mutually exclusive and exhaustive.
What is the role of the prior probability in Bayes' theorem?
It represents initial belief before seeing evidence. A strong prior (very high or very low) requires strong evidence to shift significantly.
Why does Naive Bayes work despite the independence assumption being violated?
Because the rank order of posterior probabilities is often correct even when absolute values are miscalibrated, which is sufficient for classification.

Concept Map

rearranged gives

substituted into

derives

input to

input to

normalizes

outputs

expands

generalizes to

applied in

Conditional probability

Joint probability P of A and B

Bayes theorem

Prior P of A

Likelihood P of B given A

Posterior P of A given B

Evidence P of B

Law of total probability

Extended Bayes multiple hypotheses

Medical diagnosis example

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Bayes' theorem ek aisa powerful formula hai jo apko bata hai ki naye evidence ke baad apni belief ko kaise update karein. Socho ek doctor ko – initially usko lagta hai 1% chance hai ki patient ko disease hai (ye hai prior). Phir test positive ata hai. Ab doctor Bayes' theorem use karta hai: test kitna accurate hai (likelihood), disease kitna common hai (prior), aur test positive ane ki total probability (evidence) – sab combine karke posterior nikalta hai, matlab updated belief. Interesting baat ye hai ki agar disease bohot rare hai, toh bhi 95% accurate test positive aye, toh bhi actual disease hone ki probability sirf 16% ho sakti hai! Kyunki false positives (healthy log jinko test galat positive bata deta hai) true positives se zyada hote hain.

AI aur machine learning mein Bayes ka application bohot common hai. Naive Bayes classifier spam detection, sentiment analysis jaise tasks mein use hota hai. Isme aap assume karte ho ki features independent hain (jo usually galat assumption hai, isliye "naive" naam hai), lekin phir bhi practically bohot acha kaam karta hai. Bayes ka core idea simple hai: prior belief + new evidence = updated belief. Medical diagnosis se lekar email filtering tak, jahan bhi uncertainty hai aur apko probabilities ke sath kaam karna hai, Bayes theorem aapka fundamental tool hai. Isko samajhna AI ke liye bohot zaroori hai kyunki ye uncertainty ko mathematically handle karne ka clean tarika deta hai.

Go deeper — visual, from zero

Test yourself — Probability & Statistics

Connections