Contents/ Part VI Β· Probability/ Chapter 31

Probability Fundamentals

Everything in inference, from a confidence interval to a neural network, rests on probability: the mathematics of uncertainty. This chapter builds it from the ground up, the vocabulary, the three ways to assign a probability, the scale and its axioms, and the law that makes randomness reliable.

⏱️ ~13 min read
🐍 Notebook included
πŸ“Š Chapter 31

The EDA Case Studies closed the book's first half: describing, visualizing, and preparing data. Now the second half begins, and it all stands on one idea. Before we can say how confident we are in a result, we need a precise way to talk about chance.

P
Probability is a number between 0 and 1 that measures how likely an event is: 0 means impossible, 1 means certain, and everything interesting happens in between.
πŸ’¬
Born at the gambling table

Probability theory traces to a 1654 exchange of letters between Blaise Pascal and Pierre de Fermat over how to fairly split the stakes of an interrupted game of chance (the "problem of points"). It matured through Jacob Bernoulli and Laplace, and was finally put on rigorous footing by Andrey Kolmogorov in 1933, whose three axioms still define the subject. What began as a way to win bets is now the language of all of statistics and machine learning.

1

Experiments, Outcomes, and Events

Three words carry the whole subject. A random experiment is any process with an uncertain result (rolling dice, flipping a coin). The sample space is the set of every possible outcome. An event is any subset of that sample space, the outcomes that make some statement true.

Sample space of two dice: 36 outcomes, each cell showing the sum die 2 (columns) 1 2 3 4 5 6 die 1 (rows) 1 2 3 4 5 6 2 3 4 5 6 7 3 4 5 6 7 8 4 5 6 7 8 9 5 6 7 8 9 10 6 7 8 9 10 11 7 8 9 10 11 12 Reading it Sample space S = all 36 equally likely (die1, die2) pairs. Event A = {sum is 7} has 6 outcomes, so P(A) = 6 / 36 = 1/6 An event is just a subset: count its outcomes, divide by the size of S.
🎲
Simple vs compound events

A simple event is a single outcome (rolling the pair 3-and-4). A compound event bundles several (the sum is 7, which covers six different pairs). Either way, the event is a subset of the sample space, and that is all you ever need to compute its probability.

2

Three Ways to Assign a Probability

Where does a probability number actually come from? There are three honest answers, and good practice uses whichever fits the situation.

Classical theory, equally likely favorable / total no experiment needed e.g. P(seven) = 6/36 Empirical data, long-run frequency times seen / trials measured by repeating e.g. 1000 flips -> ~0.5 heads Subjective belief, given evidence degree of belief for one-off events e.g. "70% chance of rain"
ApproachProbability is…Use it when
Classicalfavorable outcomes / total outcomesOutcomes are equally likely and countable (dice, cards, fair coins)
Empiricalthe long-run relative frequency observedYou can repeat the experiment or have historical data
Subjectivea reasoned degree of beliefA one-off event with no symmetry and no repeats (this is the Bayesian view)

These are not rivals so much as different tools. The remarkable fact, coming up in section 4, is that the classical and empirical answers agree as the number of trials grows.

3

The Scale, the Axioms, and the Complement

Every probability sits on a fixed scale from 0 to 1. You can write it as a fraction, a decimal, or a percent; they all say the same thing.

The probability scale: 0 (impossible) to 1 (certain) 00.250.50.751 impossibleeven chancecertain two sixes (0.03) a seven (0.17) heads (0.50) not a seven (0.83) P(a seven) + P(not a seven) = 0.17 + 0.83 = 1
πŸ“
Kolmogorov's three axioms (1933)

All of probability follows from three simple rules. For any event A in a sample space S: (1) P(A) is never negative; (2) P(S) = 1 (something in the sample space is certain to happen); (3) if two events cannot both occur, the probability of one or the other is the sum of their probabilities. Everything else, including every rule in the next chapter, is a consequence.

The first and most useful consequence is the complement rule: since something must happen, the probability an event does not occur is P(not A) = 1 − P(A). It is the easy route to any "at least one" question: P(at least one six in two rolls) = 1 − (5/6)² = 0.31, far simpler than counting all the ways to get a six.

4

The Law of Large Numbers, and a Famous Trap

Here is the bridge between the classical and empirical views. The Law of Large Numbers (Jacob Bernoulli, 1713) says that as you repeat an experiment, the observed relative frequency closes in on the true probability. Flip a fair coin a few times and anything can happen; flip it thousands of times and the share of heads settles near 0.5.

More trials, less luck: the proportion settles toward the true probability 0.5 number of flips (the more you do, the closer the proportion of heads gets to 0.5) 1.0 0.0
⚠️
The gambler's fallacy

The Law of Large Numbers is about the long run, not the next trial. After five heads in a row, tails is not "due", the coin has no memory, and the next flip is still 50/50. Independent events do not self-correct. Confusing "rare over many trials" with "owed right now" is the single most common, and most expensive, misreading of probability.

5

Probability in Machine Learning & AI

Probability is not just the warm-up for inference, it is the language modern models speak. A trained classifier or language model rarely returns a hard answer; it returns a probability distribution, and we read that distribution to make a decision.

A classifier's output is a probability distribution over the classes catdogfoxowl 0.620.270.080.03 argmax: predict "cat" all bars ≥ 0 and sum to 1 (Kolmogorov's axioms): take the top for a label, or sample from it to generate

The set of classes is a sample space, each class is an event, and the model's raw scores are squeezed by a softmax so they are non-negative and sum to 1, exactly the axioms from section 3. Pick the largest for a prediction, or sample from the distribution to let a language model write.

Fundamental (this chapter)In ML / AI it becomesConcrete example
Sample space & eventsThe set of labels or tokens a model chooses amonga classifier over {cat, dog, fox}; an LLM over its vocabulary
Axioms: bars sum to 1The softmax output layerturns raw scores into a valid probability distribution
Empirical probability + LLNLearning from data; Monte Carlo estimationestimate P from millions of examples; more data, tighter estimate
Subjective probabilityBayesian priorsencode belief before data, then update after seeing it
Complement ruleBinary classificationP(not spam) = 1 − P(spam)
πŸ€–
Why this matters for AI research

A trained model almost never outputs a single answer; it outputs a distribution, and we choose how to read it (argmax for a label, or sampling for a language model). The Law of Large Numbers is why training works at all: averaging a loss or gradient over a large batch converges to its true expected value, so bigger, cleaner data gives steadier learning. And calibration, whether a model's stated 0.9 really means right about 90% of the time, is an active research concern built directly on the empirical view of probability.

🐍

See probability in action

The companion notebook builds the two-dice sample space, computes the classical distribution of the sum, then simulates thousands of coin flips and die rolls to watch the Law of Large Numbers converge. It uses the complement rule for an "at least one" problem, and puts the gambler's fallacy to the test by checking what really happens right after a winning streak.

πŸ““ View Notebook (code & outputs) β–Ά Open in Colab ⬇ View / Download on GitHub

View opens the rendered notebook instantly (no setup). Open in Colab runs & edits it live in your browser. To run locally, install numpy, pandas, matplotlib and launch jupyter notebook.

πŸŽ“ Key Takeaways

  • βœ“Experiment, sample space, event are the three building blocks; an event is a subset of the sample space.
  • βœ“Three ways to assign probability: classical (favorable/total), empirical (long-run frequency), subjective (degree of belief).
  • βœ“Probabilities live on [0, 1] and obey Kolmogorov's three axioms; the complement rule P(not A) = 1 − P(A) is the workhorse.
  • βœ“The Law of Large Numbers makes empirical frequencies converge to true probabilities as trials grow.
  • βœ“The gambler's fallacy is a fallacy: independent events have no memory, the next trial is unaffected by the last.
6

Practice Challenges

Five short challenges, beginner to intermediate. Try them on paper or in Python before checking the solutions.

1

Build a sample space

Flip a fair coin twice. Write the full sample space, then list the outcomes in "exactly one head" and "at least one head".

Hint: 4 equally likely outcomes; an event is a subset.
2

Classical probability

Using that sample space, compute P(exactly one head) and P(at least one head) by counting favorable over total.

Hint: 2/4 and 3/4.
3

Empirical vs theoretical

Estimate P(at least one head in two flips) by simulating 50,000 experiments, and compare to the theoretical value.

Hint: simulate, take the mean of the indicator; expect ~0.75.
4

Use the complement

A die is rolled three times. Find P(at least one six) with the complement rule, then verify by simulation.

Hint: 1 − (5/6)³ β‰ˆ 0.42.
5

No such thing as "due"

Simulate a fair coin. After every run of four tails, what fraction of the next flips are heads? Does the streak make heads more likely?

Hint: about 0.5; independence means no memory.
βœ…
Check your work

A fully-worked solutions notebook walks through all five challenges in the same visual style. Try them yourself first, then compare.

πŸ““ View Solutions β–Ά Open Solutions in Colab ⬇ View / Download on GitHub
7

Quiz: Test Yourself

Eight quick questions on probability fundamentals. Answer them, hit Check Answers, and keep refining until you score 100%. Your progress is saved, so you can hop back to the chapter and return anytime.