Sample Space and Events
Probability Foundations
The Building Blocks of Every Probability Problem
Every probability question starts with a simple question: what can possibly happen? Sample spaces and events give you the language to describe the unknown — and once you can describe it, you can measure it.
Key things this concept helps with:
- Defining outcomes — Enumerate every possible result of a random experiment
- Grouping outcomes into events — Work with subsets that match conditions you care about
- Combining events with set operations — Use union, intersection, and complement to build complex scenarios from simple ones
Master this, and every probability formula that follows will make intuitive sense.
What is a Sample Space?
Definition
The sample space is the set of all possible outcomes of a random experiment. Each outcome is called a sample point. The sample space is the foundation upon which probability is built.
DfSample Space
The sample space (S) of an experiment is the set of all possible outcomes. Each outcome is called a sample point. The sample space is the foundation upon which probability is built.
import numpy as np
import matplotlib.pyplot as plt
# Common sample spaces
coin_sample_space = {'Heads', 'Tails'}
die_sample_space = {1, 2, 3, 4, 5, 6}
card_sample_space = [f"{rank} of {suit}"
for suit in ['Hearts', 'Diamonds', 'Clubs', 'Spades']
for rank in ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']]
print(f"Coin: {coin_sample_space}")
print(f"Die: {die_sample_space}")
print(f"Cards: {len(card_sample_space)} outcomes")
Events
An event is any subset of the sample space.
DfEvent
An event is a subset of the sample space. It is a collection of one or more outcomes that satisfy a particular condition. An event occurs if any of its outcomes occur.
| Event Type | Definition | Example (Die) |
|---|---|---|
| Simple event | Single outcome | {3} |
| Compound event | Multiple outcomes | {2, 4, 6} (even) |
| Impossible event | Empty set ∅ | {7} |
| Certain event | Entire sample space S | {1,2,3,4,5,6} |
Set Operations
Union
Here,
- =Elements in A or B or both
Intersection
Here,
- =Elements in both A and B
Complement
Here,
- =Elements in S but not in A
# Set operations for probability
S = {1, 2, 3, 4, 5, 6} # Die sample space
A = {1, 2, 3} # Event A: outcome ≤ 3
B = {2, 4, 6} # Event B: even number
union = A | B # A ∪ B
intersection = A & B # A ∩ B
complement_A = S - A # A^c
difference = A - B # A \ B
print(f"S = {S}")
print(f"A = {A}, B = {B}")
print(f"A ∪ B = {union}")
print(f"A ∩ B = {intersection}")
print(f"A^c = {complement_A}")
print(f"A \\ B = {difference}")
Venn Diagram Visualization
fig, ax = plt.subplots(figsize=(8, 6))
# Draw Venn diagram
from matplotlib.patches import Circle
c1 = Circle((0.35, 0.5), 0.3, alpha=0.3, color='blue', label='A')
c2 = Circle((0.65, 0.5), 0.3, alpha=0.3, color='red', label='B')
ax.add_patch(c1)
ax.add_patch(c2)
ax.text(0.2, 0.5, 'A only', ha='center', va='center', fontsize=12)
ax.text(0.5, 0.5, 'A ∩ B', ha='center', va='center', fontsize=12)
ax.text(0.8, 0.5, 'B only', ha='center', va='center', fontsize=12)
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_aspect('equal')
ax.set_title('Venn Diagram: Events A and B')
ax.axis('off')
plt.savefig('venn-diagram.png', dpi=150)
plt.show()
Sample Space in Machine Learning
| ML Application | Sample Space Usage | Why |
|---|---|---|
| Classification | Sample space = all classes | Model outputs must cover all outcomes |
| Generation models | Sample space = data distribution | GANs, diffusion models generate from space |
| Reinforcement learning | Sample space = states/actions | MDP framework |
import numpy as np
from sklearn.datasets import load_iris
# Sample space concept in classification
iris = load_iris()
sample_space = set(iris.target_names)
print(f"Sample space (Iris classification): {sample_space}")
print(f"All possible outcomes: {list(sample_space)}")
print(f"Model must output probabilities for ALL outcomes in sample space")
Key Takeaways
Sample space = set of all possible outcomes of an experiment
Event = any subset of the sample space
Union (A ∪ B): outcomes in A or B (or both). Intersection (A ∩ B): outcomes in both A and B.
Python set operations (|, &, -, ^) map directly to probability set operations
Probability begins with counting — and set theory is the language that lets you count with precision.