Module 8 · Probability: Reasoning About Uncertainty · Lesson 26 of 51
Events, rules and conditional probability
Probability as long-run frequency, the complement, addition and multiplication rules, independence, and conditional probability read straight from a data table.
In this lesson · about 40 minutes
- Use the complement, addition and multiplication rules
- Compute conditional probabilities from a crosstab
- Test whether two events are independent
Try it · data lab
Probability simulator
Run random trials and watch the observed share settle down to the true probability. Then roll two dice thousands of times.
The rules
- Complement: P(not A) = 1 − P(A). "At least one" problems are easiest this way: P(at least one of 3 customers pays cash) = 1 − P(none do).
- Addition: P(A or B) = P(A) + P(B) − P(A and B). Subtract the overlap so it isn't counted twice. If A and B can't both happen (mutually exclusive), the overlap is 0.
- Conditional: P(A | B) = P(A and B) ÷ P(B), "the probability of A given B".
- Multiplication: P(A and B) = P(A) × P(B | A). If A and B are independent (knowing one tells you nothing about the other), this is simply P(A) × P(B).
Reading probabilities from data
With real data, probabilities are shares of rows. pd.crosstab(orders["branch"], orders["payment"], normalize="index") gives P(payment | branch) in each row. normalize="all" gives joint probabilities, P(branch and payment).
Independence check
If P(App | Campus) ≈ P(App), branch doesn't change the chance of paying by app: they're independent. If one branch has a very different rate, they're not, and the chi-square test from Module 7 tells you whether the gap is bigger than chance.
Probabilities from the orders table
Exercise
Morning coffee
A morning column (hour < 11) is ready. Set p_coffee to P(category is Coffee), p_coffee_morning to P(Coffee | morning), and p_morning_coffee to P(morning | Coffee). Round all three to 3 decimals.
Code that runs before yours
import pandas as pd
orders = pd.read_csv("kc_orders.csv")
orders["morning"] = orders["hour"] < 11Exercise
At least one cash payer
Each customer pays cash with probability 0.15, independently. Set p_none to the probability that none of the next 8 customers pays cash, and p_at_least_one to the probability that at least one does. Round to 4 decimals.
Check your understanding0 of 3 correct
Quiz score: 0 of 3
Exercises solved: 0 of 2
Written by Noviq Academy in its own words. Kettle & Crumb and all its data are made up for teaching; any resemblance to a real business is a coincidence. Python runs in your browser with Pyodide, so results can differ slightly from your own computer. Power BI, Tableau and other product names belong to their owners. Read-aloud uses your device's built-in voices.