Conditional Probability
P(A|B) — the probability of A given that B has already happened
Free tier: read the explanation here. Upgrade to Pro for Drills, Speed challenges & Mastery badges.
UpgradeKnowledge Debt detected
You can study this freely — but your score may plateau if these foundations have gaps. The Mastery badge requires them to be solid.
Explanation
Conditional probability P(A|B) asks: "Given that B occurred, what is the probability of A?"
P(A|B) = P(A and B) / P(B)Example: In a class, 60% are female, 30% are female AND study engineering. P(engineering | female) = ? `` P(E|F) = P(E and F) / P(F) = 0.30 / 0.60 = 0.5 `` Half of the female students study engineering.
Bayes' Theorem — flips the conditioning: `` P(A|B) = P(B|A) × P(A) / P(B)
Why this matters for ML:
- Naive Bayes classifiers are built entirely on conditional probability
- P(spam | "free money") — the probability the email is spam given it contains "free money"
- Every probabilistic model reasons about conditional probabilities
Examples
Medical test example
Bayes' theorem reveals counter-intuitive results about rare diseases
# Disease prevalence: 1% of population
# Test sensitivity: P(positive | disease) = 0.99
# False positive rate: P(positive | no disease) = 0.05
# Bayes: P(disease | positive test) = ?
p_disease = 0.01
p_pos_given_disease = 0.99
p_pos_given_no_disease = 0.05
p_pos = (p_pos_given_disease * p_disease +
p_pos_given_no_disease * (1 - p_disease))
p_disease_given_pos = (p_pos_given_disease * p_disease) / p_pos
print(f"{p_disease_given_pos:.2%}") # 16.67%
# Even with a 99% accurate test, a positive result
# means only 16.7% chance you have the disease!How well did you understand this?