Gradient LabStart the lesson

Lessons › Chapter 2: Math toolkit

Probability basics

Flip a coin 10 times: H T H H T T H T H H. Yellow is heads, blue is tails. Each flip is random, but patterns appear over many flips.

Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.

Start the interactive lesson

Step by step

Story

How sure are we?

The board doesn’t want a flat yes or no on each loan. They want to know how likely it is to be repaid.

Concept

Flipping a coin

Flip a coin 10 times: H T H H T T H T H H. Yellow is heads, blue is tails. Each flip is random, but patterns appear over many flips.

Build

Probability is a fraction

Group the flips. 6 of 10 are heads, so our estimate of P(heads) is 6 / 10 = 0.6. With more flips this settles near the true value, 0.5.

Build

Rolling a die 30 times

Each face of a fair die has probability 1/6. Roll 30 times and the counts come out roughly even: about 5 of each, with some random wobble.

Key idea

All outcomes add to 1

Stack every roll into one tower. Each color’s share of the tower is its probability, and the shares always add up to the whole: 1, or 100%.

Insight

Models output probabilities

A classifier looking at a photo does not just say “cat”. It gives a probability for every class: cat 0.7, dog 0.2, bird 0.1. They add up to 1, and the biggest one is the answer.

Real life

In real life: “70% chance of rain”

A 70% rain forecast means that on days like this one, it rained about 7 times out of 10. Weather models output a probability for each hour, the same way a classifier outputs a chance for each answer.

Quick check: A model says P(spam) = 0.9. What is P(not spam)?

The two outcomes must add to 1, so 1 − 0.9 = 0.1.

Pseudocode

# probability = how often, out of all tries
flips = flip a coin 10 times
chance of heads = count(heads) / 10    # 6/10 = 0.6

rolls = roll a die 30 times
chance of six = count(six) / 30        # about 1/6

chances = model.guess(photo)    # cat 0.7, dog 0.2, bird 0.1
add up all chances              # always 1