Conditional probability is the probability of A when we already know that B happened. It is written P(A | B), read "A given B".
P(A | B) = P(A and B) ÷ P(B)
Knowing B shrinks the world to the outcomes in B; we then ask how many of those are also in A.
From a table of counts
100 students: 40 study daily, and 30 of those pass; of the 60 who do not, 24 pass.
| Habit | Pass | Fail | Total |
|---|---|---|---|
| Study daily | 30 | 10 | 40 |
| Do not | 24 | 36 | 60 |
P(pass | study daily) = 30 ÷ 40 = 0.75, but P(pass | do not) = 24 ÷ 60 = 0.4. Studying and passing are not independent.
Without replacement
Draw two cards. P(first is an ace) = 4/52. If it was, 3 aces remain among 51 cards: P(second is an ace | first was) = 3/51. Both are aces with probability 4/52 × 3/51.
from fractions import Fraction
pass_if_study = Fraction(30, 40)
pass_if_not = Fraction(24, 60)
print("P(pass | study) =", pass_if_study)
print("P(pass | not) =", pass_if_not)
first = Fraction(4, 52)
second_given_first = Fraction(3, 51)
print("P(two aces) =", first * second_given_first)Common mistakes
- Confusing P(A | B) with P(B | A). "Most people who pass study daily" is not the same as "most people who study daily pass". The next lesson is about exactly this.
Quick check
My notes
Write down what you want to remember from this lesson. Notes are saved on this device as you type, and appear on your dashboard.