Why Probability for Machine Learning#
Machine learning operates on uncertainty. A classifier outputs a confidence score, not a deterministic label. A reinforcement learning agent acts in stochastic environments where the same action does not always produce the same result. A generative model learns a distribution over data, not a single point estimate.
Probability gives us the language to describe this uncertainty precisely. It tells us how to update beliefs when we see data (Week 5), how to quantify the spread of an estimator (Week 10), and how to measure the difference between distributions (Week 11). The courses on Reinforcement Learning and Generative Models speak this language fluently — this course builds your vocabulary from the ground up.
The approach we take is axiomatic: we agree on three simple rules that any coherent assignment of probabilities must obey. From those rules, everything else follows.
Sample Spaces and Events#
Every probabilistic model starts with a sample space — the set of all possible outcomes of an experiment.
Examples:
- Toss a fair coin: .
- Roll a six-sided die: .
- Measure tomorrow's temperature (in °C): (or an interval).
- Two coin tosses: .
An event is a subset of — a collection of outcomes about which we can ask "what is the probability?".
Example — die roll. Let . The event "roll an even number" is . The event "roll at least 5" is .
Set operations on events (since events are sets, set language applies):
- Union : the event that or occurs (or both).
- Intersection : the event that and both occur.
- Complement : the event that does not occur.
- Disjoint (mutually exclusive) events: , meaning they cannot both happen on the same realisation.
For the die example: (even and at least 5), .
Kolmogorov Axioms#
A probability measure assigns a number in to each event. Andrey Kolmogorov (1933) gave three axioms that any valid must satisfy:
- Non-negativity. For every event , .
- Normalisation. — some outcome must occur.
- Countable additivity (finite version). If are pairwise disjoint, then
For most of this course we use the finite version of axiom 3: probabilities of mutually exclusive events simply add. The infinite (countable) version handles sequences, but the intuition is identical.
What the axioms give us — useful consequences:
- (the impossible event).
- Complement rule: .
- Monotonicity: If , then .
- Inclusion-exclusion (two events):
The inclusion-exclusion formula corrects for double-counting: adding counts the intersection twice, so we subtract it once.
Worked example. In a class of 100 students, 60 study calculus (), 45 study linear algebra (), and 20 study both. What is the probability a randomly chosen student studies at least one of the two subjects?
So 85% study at least one. The complement rule gives .
Finite Spaces and Counting#
When is finite and every outcome is equally likely, probability reduces to counting:
where denotes cardinality (number of elements). This is the "classical" definition of probability — but it only works when the equiprobable assumption is justified (fair coins, fair dice, well-shuffled cards, random sampling).
Worked example — two dice. Roll two fair six-sided dice (36 equally likely ordered pairs). What is the probability that the sum is 7?
The outcomes that sum to 7 are — six outcomes. So
Inclusion-exclusion with counting (two events):
For two events and in a finite equiprobable space:
Dividing through by recovers the probability inclusion-exclusion formula above. The three-event version is:
The pattern: add singles, subtract pairs, add triples — alternating signs so every outcome in the union is counted exactly once.
Discrete vs Continuous Setup#
So far we have thought of as a finite or countably infinite set (e.g., ). In that case we can list the outcomes and assign a probability to each , with . For any event , .
But many quantities of interest — temperature, height, the weight of a neural network — are continuous. The sample space is an interval or all of . Here the list-and-sum approach breaks down: any single real number has probability zero (think of picking a point on a line — there are uncountably many of them, so each gets measure zero).
For continuous spaces, probability is assigned via a density function that integrates to 1 over the space:
This is the subject of Week 2, where we introduce random variables, PMFs, PDFs, and CDFs systematically. For now, the key distinction is:
| Discrete | Continuous | |---|---| | is finite or countable | is an interval or | | | | | Single outcomes can have positive probability | Single outcomes have probability zero | | Motivating examples: coins, dice, cards | Motivating examples: measurements, sensor readings |
The axiomatic framework (Kolmogorov's three rules) works in both settings. The only difference is whether we sum or integrate to accumulate probability over an event.
Warning — Do not conflate the two. In a continuous setting, is 0, even though the density may be positive. Density is not probability — it is probability per unit. Week 2 makes this crisp.
In a survey, 40% of respondents own a dog (A), 30% own a cat (B), and 15% own both. Using inclusion-exclusion, what percentage owns a dog or a cat (or both)?
Knowledge check#
Which of Kolmogorov's axioms would be violated if we assigned P(A) = −0.1 to some event?
Browser lab#
Simulate die rolls and compare empirical frequencies to the axiom-based probabilities of events.
import numpy as np
import matplotlib.pyplot as plt
def roll_die(n):
return np.random.randint(1, 7, size=n)
n_rolls = 6000
rolls = roll_die(n_rolls)
events = {
"Even (2,4,6)": (rolls % 2 == 0),
"≥ 5 (5,6)": (rolls >= 5),
"Prime (2,3,5)": np.isin(rolls, [2, 3, 5]),
"Divisible by 3 (3,6)": (rolls % 3 == 0),
}
true_probs = {"Even (2,4,6)": 0.5, "≥ 5 (5,6)": 1/3,
"Prime (2,3,5)": 0.5, "Divisible by 3 (3,6)": 1/3}
fig, axes = plt.subplots(2, 2, figsize=(8, 7))
for ax, (name, mask) in zip(axes.flat, events.items()):
empirical = mask.sum() / n_rolls
ax.bar(["Axiom (true)", "Empirical"], [true_probs[name], empirical],
color=["tab:blue", "tab:orange"])
ax.set_ylim(0, 1)
ax.set_title(name)
ax.set_ylabel("Probability")
fig.suptitle(f"Empirical vs True Probabilities ({n_rolls} rolls)", fontsize=13)
plt.tight_layout()
plt.show()
print("Empirical frequencies:")
for name, mask in events.items():
print(f" {name}: {mask.sum() / n_rolls:.4f} (true: {true_probs[name]:.4f})")