Conditional Probability
Master conditional probability, multiplication rule, and reduced sample spaces.
Introduction
Conditional probability captures how our beliefs update with new information. It's fundamental to Bayes' theorem, machine learning, and all statistical inference.
Learning Objectives:
- Master conditional probability definition
- Apply the multiplication rule
- Understand reduced sample spaces
Conditional Probability
The conditional probability of given is:
Read as "probability of given has occurred."
Intuition: When occurs, the sample space "shrinks" to . We ask: within this reduced space, what fraction contains ?
import random
def simulate_conditional(n=10000):
# Die roll: P(even | >3)
count_B = 0 # >3
count_A_and_B = 0 # even AND >3
for _ in range(n):
roll = random.randint(1, 6)
if roll > 3:
count_B += 1
if roll % 2 == 0:
count_A_and_B += 1
p_A_given_B = count_A_and_B / count_B if count_B > 0 else 0
print(f"P(even | >3) simulated: {p_A_given_B:.4f}")
print(f"Theoretical: 2/3 = 0.6667 (outcomes {{4,5,6}}, even are {{4,6}})")
simulate_conditional()Multiplication Rule
Rearranging the definition:
Use: Calculate joint probabilities from conditional ones.
Key Takeaways
- Definition:
- Multiplication rule:
- Reduced space: Conditioning shrinks sample space to
Next: Law of total probability and Bayes' theorem!
Interactive Playground
Experiment with these interactive tools to deepen your understanding.
🔮 Interactive: Bayes' Theorem Calculator
A disease affects 1% of the population. A test is 95% accurate for positive cases and has 5% false positive rate.
Of those who test positive (59), only 10 actually have the condition.
💡 Base Rate Neglect: Even with a highly accurate test, a low prior probability dramatically reduces the posterior. This is why false positives dominate when testing for rare events!
⭕ Interactive: Venn Diagram Visualizer
💡 Conditional Probability: P(A|B) zooms into circle B and asks what fraction is also in A. Notice how P(A|B) changes as you adjust the intersection!
🔗 Interactive: Independence Tester
Generate data from independent or dependent events and see how the statistics differ.
💡 Key Insight: For independent events, P(A|B) = P(A). The intersection P(A ∩ B) equals the product P(A) × P(B). Generate dependent data to see how this breaks!