Every modern classifier hands you a number between 0 and 1 and calls it a probability. To read that number correctly, to know whether a model that is "99% confident" should actually be trusted, you need the small, sturdy core of probability theory. This lesson builds that core from scratch: the space of possible outcomes, the three rules every probability obeys, how one event shifts the odds of another, and the single formula (Bayes' theorem) that quietly powers spam filters, diagnostic models, and the loss functions you optimize every day.
Sample spaces and events
Start with an experiment whose outcome is uncertain. The sample spaceΩ is the set of all possible outcomes. For a single die roll, Ω={1,2,3,4,5,6}. An event is any subset of , for example "the roll is even" is the event . Probability is a function that assigns each event a number measuring how likely it is.
Ask the tutor
Ask about this lesson, or about anything in AI. Answers cite the lessons they draw on.
Finished this lesson?
Mark it complete to earn XP, keep your streak, and schedule a review.
Ω
{2,4,6}
P
The three axioms
Every valid probability obeys three rules (Kolmogorov's axioms):
Non-negativity:P(A)≥0 for every event A.
Normalization:P(Ω)=1, something in the sample space must happen.
Additivity: if A and B cannot both occur (they are disjoint), then P(A∪B)=P(A)+P(B).
Everything else, including Bayes' theorem, is derived from these three lines.
Conditional probability and independence
New information changes the odds. The probability of Agiven that B occurred is
P(A∣B)=P(B)P(A∩B),P(B)>0.
Intuitively, you shrink your world down to the outcomes where B is true, then ask what fraction of that smaller world also has A. Two events are independent when learning B tells you nothing about A, i.e. P(A∩B)=P(A)P(B), equivalently P(A∣B)=P(A).
Bayes' theorem
Rearranging the definition both ways gives us a way to flip a conditional:
This lets us turn P(evidence∣cause), which is often measurable, into P(cause∣evidence), which is what we actually want.
Worked example: a medical test
A disease affects 1% of people. A test detects it 99% of the time when present (P(+∣D)=0.99) but also fires falsely 5% of the time in healthy people (P(+∣¬D)=0.05). You test positive. What is P(D∣+)?
1Write the piecesPrior P(D)=0.01, sensitivity P(+|D)=0.99, false-positive rate P(+|¬D)=0.05.
2Total probability of a positiveP(+) = 0.99·0.01 + 0.05·0.99 = 0.0099 + 0.0495 = 0.0594.
3Apply BayesP(D|+) = 0.0099 / 0.0594 ≈ 0.167.
Only about 16.7%, a positive test still leaves you probably healthy, because the disease is rare. Natural frequencies make this obvious. Imagine 10,000 people:
Group
Count
Test positive
Have disease (1%)
100
99
Healthy (99%)
9,900
495
Total positives
594
Of the 594 positives, only 99 are truly sick: 99/594≈16.7%, matching Bayes exactly.
Random variables and expectation
A random variableX maps outcomes to numbers (a reward, a count, a loss). Its expectation is the probability-weighted average:
E[X]=∑xxP(X=x).
Suppose an agent's per-step reward is +10 with probability 0.2, +1 with probability 0.5, and −5 with probability 0.3:
E[X]=10(0.2)+1(0.5)+(−5)(0.3)=2+0.5−1.5=1.0.
The agent nets 1.0 per step on average, the quantity reinforcement learning tries to maximize.
Why this is everywhere in AI
Training a classifier with cross-entropy loss is minimizing an expectation
over your data, and Naive Bayes classifiers apply Bayes' theorem directly. The
16.7% result is exactly why calibration matters: a confident-looking output
can still be wrong when the base rate is low.
Common mistakes
Base-rate neglect. Ignoring the prior P(D) makes a 99%-accurate test look far more decisive than the 16.7% above. Rare events stay rare even after positive evidence.
Confusing P(A∣B) with P(B∣A). "99% of sick people test positive" is not "99% of positive people are sick." Bayes' theorem exists precisely to convert one into the other.
Assuming independence.P(A∩B)=P(A)P(B) only holds when events are independent; misusing it inflates or deflates joint probabilities.