Rules & conditional probability
Step 12 of 18 in Foundations · Concept · Easy
P(A|B) is the probability of A once you know B happened. Mixing up P(A|B) and P(B|A) is the most common reasoning error in data work.
The lesson
A probability is a number from 0 to 1. Three rules cover most of what you need: P(not A) = 1 − P(A). P(A or B) = P(A) + P(B) − P(A and B). And the conditional: P(A | B) = P(A and B) / P(B), the probability of A once you zoom in to the cases where B happened.
- P(free | spam) = 15 / 20 = 0.75
- P(spam | free) = 15 / (15 + 10) = 0.6
- Same 15 emails on top, different group underneath. They are different questions.
A and B are independent when knowing one tells you nothing about the other: P(A | B) = P(A), which is the same as P(A and B) = P(A)·P(B).
Monty Hall, briefly: your first pick is right 1 time in 3. The host then opens a door he knows hides a goat. Switching wins exactly when your first pick was wrong, so 2 times in 3.
Common mistake. P(A | B) is not P(B | A). "Most spam says free" does not mean "most emails that say free are spam". Always ask what is underneath the fraction.
Check yourself
You roll a fair die. What is P(six | the roll is even)?
Show the answer
0.3333. Zoom in to the even rolls: 2, 4, 6. One of those three is a six: 1/3.
P(A) = 0.5 and P(B) = 0.4, and they are independent. What is P(A and B)?
Show the answer
0.2. Independent events multiply: 0.5 × 0.4 = 0.2.
Monty Hall with 100 doors: you pick one, the host opens 98 goats. Switching wins with probability:
- 1/2
- 1/100
- 99/100
Show the answer
99/100. Your first pick is right 1 time in 100. Every other time the car is behind the one door the host left shut.
Build it
Simulate Monty Hall
Simulate 100,000 games of Monty Hall with switch and stay strategies.
Done when: Switching wins about 2/3 of the time and you can explain why.
Runs in your browser: write the code on the map and the tests mark it.
Resources
- Wikipedia: Conditional probability Article
- Seeing Theory Article
- StatQuest Video
- Think Bayes (free book) Book
Earn this star
On the map, your answers are marked and you log what you built. Finish the step and its star lights.
Open this step on the map