Why probability?#
Data science is about making decisions under uncertainty - will this customer buy, is this transaction fraud, did the new website design really increase sales? Probability is the language for "how likely".
A probability is a number from 0 (impossible) to 1 (certain).
Experiments, sample spaces and events#
| Term | Meaning | Example (roll a die) |
|---|---|---|
| experiment | something with an uncertain result | rolling a die |
| sample space S | all possible outcomes | {1, 2, 3, 4, 5, 6} |
| event A | a set of outcomes we care about | "even" = |
When all outcomes are equally likely:
P(A) = (number of outcomes in A) ÷ (number of outcomes in S)
P(even) = 1/2 P(>4) = 1/3
Rules of probability#
| Rule | Formula |
|---|---|
| complement | P(not A) = 1 − P(A) |
| addition (any events) | P(A or B) = P(A) + P(B) − P(A and B) |
| addition (mutually exclusive) | P(A or B) = P(A) + P(B) |
| multiplication (independent) | P(A and B) = P(A) × P(B) |
| multiplication (general) | P(A and B) = P(A) × P(B given A) |
Example. A card is drawn from a pack of 52. P(king or heart) = 4/52 + 13/52 − 1/52 = 16/52 ≈ 0.31 (the king of hearts was counted twice).
"At least one" problems are easiest with the complement. P(at least one six in 4 rolls) = 1 − P(no six in 4 rolls) = 1 − (5/6)⁴ ≈ 0.518.
Simulation - checking with Python#
The law of large numbers says that if you repeat an experiment many times, the fraction of times an event happens gets close to its probability. Let's check the "at least one six" answer with 100,000 simulated games.
Independent events#
Two events are independent if one happening doesn't change the chance of the other - two coin tosses, or two dice. Drawing two cards without putting the first back is not independent.
Independent का मतलब है एक घटना दूसरी पर असर नहीं डालती। सिक्का पहली बार Head आए या Tail, दूसरी बार Head आने की संभावना फिर भी 1/2 है। लेकिन ताश से बिना वापस रखे दूसरा पत्ता निकालें तो पहली घटना ने पत्ते कम कर दिए - ये dependent हैं।
Conditional probability#
P(A | B) - "probability of A given B" - only looks at the cases where B is true:
P(A | B) = P(A and B) ÷ P(B)
P(pass) = 0.78 P(pass | coaching) = 0.90 P(pass | no coaching) = 0.70
A difference in conditional probabilities shows an association, not proof of cause. Students who join coaching may also study more at home. Only a controlled experiment (like an A/B test) can show cause.
Bayes' theorem#
Bayes' theorem "reverses" a conditional probability:
P(A | B) = P(B | A) × P(A) ÷ P(B)
- P(A) - the prior: what we believed before the evidence.
- P(B | A) - the likelihood of the evidence if A is true.
- P(A | B) - the posterior: our updated belief.
It powers spam filters, medical diagnosis, fraud detection and the Naive Bayes classifier.
40% of emails are spam. The word "lottery" appears in 25% of spam and 1% of normal emails. An email contains "lottery".
P(lottery) = 0.25 × 0.40 + 0.01 × 0.60 = 0.106
P(spam | lottery) = 0.25 × 0.40 / 0.106 ≈ 0.943 - almost certainly spam.
Summary#
- P(A) = favourable / total for equally likely outcomes; probabilities lie in [0, 1].
- Complement, addition (subtract the overlap) and multiplication rules.
- Independent: P(A and B) = P(A)·P(B). Conditional: P(A|B) = P(A and B)/P(B).
- Bayes' theorem updates a prior with evidence - and shows why rare events give many false positives.
- Simulations with NumPy are a quick way to check any probability answer.