Probability Basics

Events are subsets of a sample space, and probabilities obey a few axioms; from there you get conditional probability, independence, and Bayes' rule.

Introductory · High-school mathematics · about 12 minutes

Reading map and next steps

Intuition

The idea in plain words, before the symbols.

You see one outcome, but you do not see the hidden situation that produced it. How should your belief change?

Probability starts by listing possible worlds and assigning mass to sets of worlds. An event is a subset of those worlds. Conditional probability is what happens when you learn that the true world lies inside one event: you keep only the compatible worlds and renormalize their mass back to 11.

This "filter then renormalize" picture is the foundation for likelihood, Bayesian inference, calibration, uncertainty, and losses such as cross-entropy. In machine learning, a model is often a device that assigns probabilities to possible observations or labels. The first question is not whether the model is deep; it is whether its probability statements obey the basic rules.

One caution: probability is not only long-run frequency. In Bayesian inference it can also represent degrees of belief about unknowns. Under either reading, the same rules for events, conditioning and normalization apply.

Study prompts for this section: Intuition
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

Mathematics

Definitions, assumptions and the derivation.

For this page, start with a finite probability model. A probability space is (Ω,F,P)(\Omega,\mathcal F,P):

  • Ω\Omega: sample space (all outcomes)
  • F\mathcal{F}: events (in a finite model, usually all subsets of Ω\Omega; in general, a sigma-algebra of measurable subsets)
  • PP: probability measure

For events E∈FE\in\mathcal F, the basic axioms are:

  1. P(E)≥0P(E) \ge 0
  2. P(Ω)=1P(\Omega)=1
  3. If E1,E2,…E_1,E_2,\dots are pairwise disjoint, then
P(⋃iEi)=∑iP(Ei).P\left(\bigcup_i E_i\right)=\sum_i P(E_i).

For finite examples, this reduces to adding the probabilities of disjoint pieces.

The complement rule follows:

P(Ec)=1−P(E).P(E^c)=1-P(E).

Conditional probability means updating probabilities after observing an event OO:

P(E∣O)=P(E∩O)P(O)(P(O)>0).P(E\mid O) = \frac{P(E\cap O)}{P(O)} \quad (P(O)>0).

The denominator matters. Conditioning does not merely keep E∩OE\cap O; it rescales all probability inside OO so the new total mass is 11. If P(O)=0P(O)=0, there is no mass inside the observed event to renormalize, so P(E∣O)P(E\mid O) is undefined.

The product rule is the same equation rearranged:

P(E∩O)=P(E∣O)P(O)=P(O∣E)P(E),P(E\cap O)=P(E\mid O)P(O)=P(O\mid E)P(E),

when the conditioning events have positive probability.

Independence means learning one event does not change the probability of the other:

E⊥O  ⟺  P(E∩O)=P(E)P(O).E \perp O \iff P(E\cap O)=P(E)P(O).

Equivalently, when P(O)>0P(O)>0, independence means P(E∣O)=P(E)P(E\mid O)=P(E).

Bayes' rule follows by writing the same intersection two ways:

P(E∣O)=P(O∣E)P(E)P(O).P(E\mid O) = \frac{P(O\mid E)P(E)}{P(O)}.

If C1,…,CmC_1,\dots,C_m are mutually exclusive hidden cases that cover the sample space, they form a partition. The denominator can be expanded by total probability:

P(O)=∑j=1mP(O∣Cj)P(Cj),P(O)=\sum_{j=1}^m P(O\mid C_j)P(C_j),

for hidden cases with positive prior probability.

That gives the form used in classification, diagnosis, and Bayesian updating:

P(Ci∣O)=P(O∣Ci)P(Ci)∑j=1mP(O∣Cj)P(Cj).P(C_i\mid O)=\frac{P(O\mid C_i)P(C_i)}{\sum_{j=1}^m P(O\mid C_j)P(C_j)}.

The numerator is likelihood times prior. The denominator is the total evidence. In the demo, the hidden cases are "coin A was chosen" and "coin B was chosen," while OO is the observed Head or Tail.

Study prompts for this section: Mathematics
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

Code

The same calculation as runnable code, in the notation of the derivation.

import numpy as np

rng = np.random.default_rng(0)

# Hidden state: choose coin A or coin B, then observe Head or Tail.
prior_B = 0.30
p_head_A = 0.20
p_head_B = 0.80

prior_A = 1 - prior_B

joint = {
    ("A", "H"): prior_A * p_head_A,
    ("A", "T"): prior_A * (1 - p_head_A),
    ("B", "H"): prior_B * p_head_B,
    ("B", "T"): prior_B * (1 - p_head_B),
}

assert abs(sum(joint.values()) - 1.0) < 1e-12

# Bayes numerator = likelihood times prior.
bayes_numerator = p_head_B * prior_B
evidence_H = p_head_A * prior_A + p_head_B * prior_B
posterior_B_given_H = bayes_numerator / evidence_H

assert abs(bayes_numerator - joint[("B", "H")]) < 1e-12
assert abs(evidence_H - (joint[("A", "H")] + joint[("B", "H")])) < 1e-12

print("P(H):", round(evidence_H, 3))
print("P(B and H):", round(joint[("B", "H")], 3))
print("P(H | B)P(B):", round(bayes_numerator, 3))
print("P(B | H):", round(posterior_B_given_H, 3))

# Monte Carlo check: simulate the same process.
n = 200_000
is_B = rng.random(n) < prior_B
head_probability = np.where(is_B, p_head_B, p_head_A)
heads = rng.random(n) < head_probability
print("simulation P(B | H):", round(is_B[heads].mean(), 3))
Study prompts for this section: Code
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

Demo

Change an input, predict the result, and see which quantities respond.

ExploreChange one control at a time and name what responds.An optional observation guide follows the demo.

Explore Probability Basics

Loading the interactive demo…

Observation guide

Optional and ungraded. Opening a guide saves nothing.

Choose what to inspect in Probability Basics, then open its guide.

Move the prior and likelihood sliders, then switch the observation between Head and Tail. After you reveal, the table shows the four joint probabilities. Conditioning keeps the column matching the observation and renormalizes it.

When Head is observed, the likelihoods are P(H∣A)P(H\mid A) and P(H∣B)P(H\mid B). When Tail is observed, the likelihoods are P(T∣A)=1−P(H∣A)P(T\mid A)=1-P(H\mid A) and P(T∣B)=1−P(H∣B)P(T\mid B)=1-P(H\mid B).

Watch the base rate. A coin can be very good at producing heads, but if it is rare enough, observing heads may still leave uncertainty about which coin was chosen.

Study prompts for this section: Demo
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

In focus

Concept: Probability Basics

What is the smallest example of Probability Basics you can work through by hand, and what does it show?

BeforeNo hard prerequisiteNextRandom Variables
DetailsProbability

After the first pass

Go deeper

Optional material for a second reading. Sources are always shown; the other panels open from their headings or from these links, and closing one keeps what you wrote or revealed.
What to look for in each sectionChoose a section and what you expect to see in it, then read short advice.

Section by section

Choose what to look for in each section

Events are subsets of a sample space, and probabilities obey a few axioms; from there you get conditional probability, independence, and Bayes' rule.

Choose what to look for (no demo yet)01 / Intuition
Illustration of a sample space, overlapping event regions, probability mass, and conditional renormalization cues.
What to look for

Start with the picture, metaphor, or geometric mechanism.

Choose first

Choose what you expect to see in this section of Probability Basics.

Questions to ask of the pictureChoose a part of the picture and what you expect, then read short advice.

Looking at the picture

Questions to ask of the picture

Events are subsets of a sample space, and probabilities obey a few axioms; from there you get conditional probability, independence, and Bayes' rule.

4 of 4 sections writtenNo live demo yet
Question

Which part of the picture should you look at first?

Choose first

Pick the part of the picture you expect to explain Probability Basics.

Sources

References for this page

A reference shows where an idea comes from; it does not vouch for every step on this page.
book · 2020Mathematics for Machine LearningDeisenroth, Faisal, and Ong
Why it is cited

Grounds probability basics, conditional probability, Bayes' rule, and expectation for ML readers.

Open source
book · 1933Grundbegriffe der WahrscheinlichkeitsrechnungKolmogorov
Why it is cited

Springer; in English as Foundations of the Theory of Probability (Chelsea, 1950). States the axioms of probability on a sample space and defines conditional probability.

Open source
book · 2019Introduction to Probability (2nd ed.)Blitzstein and Hwang
Why it is cited

Chapman & Hall/CRC. Chapters 1 and 2 cover sample spaces, the axioms, conditional probability, independence and Bayes' rule with the law of total probability.

Open source
What each claim rests on1 claim, each with its sources, where it appears on this page, and its caveats.

Claims and sources

Events are subsets of a sample space, and probabilities obey a few axioms; from there you get conditional probability, independence, and Bayes' rule.

Checked against the cited passages

The checks were made by this site, not by an independent reviewer.

In a finite probability model, events are subsets of a sample space whose probabilities are nonnegative, add over disjoint unions, total one on the whole space, and get renormalized when conditioning on observed evidence.
What the sources support

Mathematics for Machine Learning introduces probability for ML through probability spaces, events, conditional probability, independence, Bayes' theorem, and expectation, matching this page's finite-event an...

Where to see it on this page
Equation 1
P(⋃iEi)=∑iP(Ei).P\left(\bigcup_i E_i\right)=\sum_i P(E_i).
Equation 2
P(Ec)=1−P(E).P(E^c)=1-P(E).
Caveat

This checks the finite-event probability and conditioning bridge used here, not continuous regular conditional probabilities or philosophical interpretations of probability.

StatusChecked against the cited passages.

Checked MML chapter 6.1-6.3: it defines the sample space as all outcomes, event space as subsets of Omega, assigns each event A a probability P(A) in [0,1], and requires total mass P(Omega)=1. Its finite coin example adds the probabilities of disjoint outcomes in a union, section 6.2 defines conditional probabilities as table fractions, and section 6.3 derives Bayes' rule with evidence normalizing the posterior.

Explain it without the pageWrite your own explanation before asking for feedback. Your draft and any hints stay while this page is open.

Practice · Probability Basics

Try the idea in your own words

Events are subsets of a sample space, and probabilities obey a few axioms; from there you get conditional probability, independence, and Bayes' rule.

Concept · Selected for practice

Probability Basics

What it rests on: Sources: Mathematics for Machine Learning; Grundbegriffe der Wahrscheinlichkeitsrechnung; Introduction to Probability (2nd ed.)

Context and links
Choose a task

Explain the mechanism

For Probability Basics: What is the smallest example of Probability Basics you can work through by hand, and what does it show? Explain your answer, including what changes, why, and which assumption matters.

No answer yet

A rough first thought is enough. Your draft stays when you change tasks.

Your draft stays on this page and is cleared when you leave or reload.

A little help · Explain

Open one hint at a time. These are suggestions, not your answer or a grade.

0 of 3 hints shown for this question.

    Clearing your answer keeps this help record. Outside help is your own report; this page cannot check it.

    Where am I stuck? (optional)
    Your own description, not an automatic diagnosis

    Choose one, or leave this unspecified. Select it again to clear it.

    Take your draft to a feedback conversation

    No AI feedback runs here. You can copy a prompt to use elsewhere; nothing is sent automatically. Review the text before sharing, and leave out private information.

    Write an attempt before copying a feedback prompt.

    A draft, or an AI reply to it, is not a test of what you have learned. To check that, try a different case later without help.

    Ask about this pagePick one item on this page and copy a prompt about it into an AI assistant you already use. Notes you write here stay in this browser.
    Ask about this pageClose
    ConceptProbability BasicsSources: Mathematics for Machine Learning; Grundbegriffe der Wahrscheinlichkeitsrechnung; Introduction to Probability (2nd ed.)assert abs(sum(joint.values()) - 1.0) < 1e-12

    Your question

    Choose what your question is about

    Pick the idea, equation, source, code, claim, misconception or demo state you want to ask about. The prompt you copy includes it, so the answer can stay on that item.
    Next local actionNo local draft saved yet

    Open the draft below to save one note and next action in this browser.

    conceptProbability

    Probability Basics

    Starting question

    What is the smallest example of Probability Basics you can work through by hand, and what does it show?

    SourcesCheck the 3 cited sources listed under Sources.Notes can be saved for this item
    Points of view on this item

    Fixed prompts generated from this item. They are not comments from people or independent reviews.

    Learner’s first stepAsk what would make "Probability Basics" feel predictable rather than familiar.
    Assumption

    The 3 cited sources must support this exact item, not just the surrounding topic.

    Source-checking summary

    Connect the definition to one equation, piece of code or demo before widening the discussion.

    Proposed experiment

    Change one input, then check that the same relationship holds in the mathematics, the code and the demo.

    Next action

    You can state the mechanism in your own words

    Evidence4 checks
    ObservationChecking for a saved observation
    ActionReady for one action
    PromptLearner prompt ready to copy
    Go to this item
    01ObservationChecking what this browser has saved
    02EvidenceChecking for a saved observation
    03SourcesCheck the 3 cited sources listed under Sources.
    04Next stepSave one next action
    Local action draftNo local draft saved yetOpen when you are ready to write one next action
    Local action draft

    This draft stays in this browser and is attached to this item only.

    No local draft saved.
    Evidence to inspect
    • What the 3 cited sources say about this exact item
    • The definition, its prerequisites, and a contrasting concept
    • The equation or code that makes the concept concrete
    • One demo state that shows what stays the same as the inputs change
    What would resolve this
    • You can state the mechanism in your own words
    • You can name the prerequisite that would clear up the confusion
    • You can predict how the result changes when one input changes
    Reference idconcept/concept-notebook/probability/probability-basics concept:probability/probability-basics