Conditional Probability
Given that.
What's the chance a customer buys something, given that they opened our email? That word, given, means we only look at part of the data. That's conditional probability.

- Buys, given they opened the email
- Given narrows the data
- Conditional probability
Counting within a group
Here are a thousand customers, with whether they opened the email, and whether they bought. To find the chance of buying given opened, we keep only the people who opened, and see what share of them bought. Run it. Overall, nine percent bought. But among openers, it was twenty five percent.
import pandas as pd
df = pd.DataFrame({
"opened": [True] * 200 + [False] * 800,
"bought": [True] * 50 + [False] * 150 + [True] * 40 + [False] * 760,
})
print("P(bought): ", df["bought"].mean())
print("P(bought | opened):", df[df["opened"]]["bought"].mean())P(bought): 0.09 P(bought | opened): 0.25
The formula
The probability of A given B is the probability of both, divided by the probability of B. In words, out of all the times B happens, how often does A happen too? Classifiers in machine learning predict exactly this. The probability of a label, given the features.
| key | value |
|---|---|
| P(A | B) | P(A and B) ÷ P(B) |
| In words | of the B cases, how many are A? |
| Note | P(A | B) ≠ P(B | A) |
| Classifiers | P(label | features) |
Summary
Conditional probability is the chance of A, given that B happened. Just look inside the B group. Next, Bayes' theorem, which flips it around.
Key takeaways- Given = filter first
- P(A|B) = P(A and B) / P(B)
- Models predict P(label | features)