Construction of a Probability Space
Probability starts with a careful setup: a probability space built from three ingredients (a sample space, an event space, and a probability measure), plus a random variable that maps messy real-world outcomes to numbers we can compute with. Getting this foundation straight untangles the notation that trips up most beginners in probabilistic machine learning.
A real-life example: drawing coins from a bag
A bag holds US coins ( with probability 0.3. You care about **how many ”) into a number (1). The whole machinery below just makes this everyday move precise.
The three ingredients
A probability space models a random experiment:
- Sample space — the set of all possible outcomes. Two coin draws: \Omega = \{\$, $£, £$, ££}$.
- Event space — the collection of events (subsets of ) we can ask about. For discrete problems it’s usually all subsets.
- Probability measure — assigns each event a number , with the whole space summing to one: .
The random variable
We rarely work with directly. Instead a random variable maps each outcome to a value in a target space (often numbers). For “count the $s”:
The distribution (or law) of assigns probabilities to its values. With P(\) = 0.3$ and independent draws:
Probability = long-run frequency
One way to read : repeat the experiment many times, and the fraction of times you see value settles toward . Watch the bars (empirical frequencies) converge to the true distribution (amber ticks) as draws accumulate — the law of large numbers in action:
The empirical bars wobble at first, then lock onto the true probabilities — this is why we can estimate distributions from data.
Probability vs. statistics
- Probability: given a model, predict what data looks like (forward).
- Statistics: given data, infer the model that produced it (backward).
Machine learning is mostly the second — building a model that explains observed data — which is why probability is its foundation.
flowchart LR O["Sample space Ω
(all outcomes)"] --> X["Random variable X : Ω → T"] X --> D["Distribution P_X
(probabilities over values)"] D -.-> EST["estimate from data (statistics / ML)"]
NumPy
import numpy as np
rng = np.random.default_rng(0)
# Random variable X = number of $ in two draws, P($) = 0.3
def draw_X():
return int(rng.random() < 0.3) + int(rng.random() < 0.3)
# Simulate and estimate the distribution (law of large numbers)
N = 200_000
samples = np.array([draw_X() for _ in range(N)])
for k in [0, 1, 2]:
print(f"P(X={k}) empirical = {np.mean(samples == k):.3f}")
print("true:", {0: 0.49, 1: 0.42, 2: 0.09})import numpy as np
rng = np.random.default_rng(0)
# Random variable X = number of $ in two draws, P($) = 0.3
def draw_X():
return int(rng.random() < 0.3) + int(rng.random() < 0.3)
# Simulate and estimate the distribution (law of large numbers)
N = 200_000
samples = np.array([draw_X() for _ in range(N)])
for k in [0, 1, 2]:
print(f"P(X={k}) empirical = {np.mean(samples == k):.3f}")
print("true:", {0: 0.49, 1: 0.42, 2: 0.09})P(X=0) empirical = 0.490
P(X=1) empirical = 0.420
P(X=2) empirical = 0.090
true: {0: 0.49, 1: 0.42, 2: 0.09}P(X=0) empirical = 0.490
P(X=1) empirical = 0.420
P(X=2) empirical = 0.090
true: {0: 0.49, 1: 0.42, 2: 0.09}Why this matters for ML
- Everything is a random variable: features, labels, weights, and predictions are all modeled as random variables with distributions.
- The frequentist view (probability = long-run frequency) justifies estimating probabilities by counting — the basis of empirical risk and validation.
- Clean separation of , , and demystifies the lazy notation you’ll see everywhere.
🧪 Try It Yourself
Exercise 1 – A random variable as a lookup
Exercise 2 – Distribution sums to one
Exercise 3 – Estimate a probability by simulation
Recap
- A probability space has a sample space, event space, and probability measure ().
- A random variable maps outcomes to a target space; its distribution assigns probabilities to values.
- Probabilities are long-run frequencies — the reason we can estimate them from data.
Next: the two flavors of distribution — discrete and continuous.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
