Lessons › Chapter 2: Math toolkit
Mean, variance and the normal curve
Eight measurements: 2, 4, 4, 4, 5, 5, 7, 9. Repeated values stack up. Two questions matter: where is the center, and how spread out is it?
Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.
Start the interactive lessonStep by step
Typical, and how spread out
Before modeling anything, Leo summarizes customer balances: what’s typical, and how widely they vary.
Data on a number line
Eight measurements: 2, 4, 4, 4, 5, 5, 7, 9. Repeated values stack up. Two questions matter: where is the center, and how spread out is it?
The mean is the balance point
Add everything and divide by the count: 40 / 8 = 5. If the line were a seesaw, the mean is where it would balance.
How far is each point?
Measure each point’s distance from the mean: −3, −1, −1, −1, 0, 0, +2, +4. Some are negative, so we cannot just average them. They would cancel out.
Variance: the average squared distance
Square each distance so nothing is negative, then average them: (9+1+1+1+0+0+4+16) / 8 = 4. That is the variance. Its square root, 2, is the standard deviation: how far a typical point sits from the middle.
Many samples make a bell
Measure lots of natural quantities (heights, test scores, sensor noise) and the histogram forms a bell shape: the normal distribution. Most values sit near the mean, and few are far out.
Standardize: mean 0, std 1
Shift everything so the middle sits at 0, then squeeze it so the spread is 1. When every feature shares the same scale, models learn faster and treat each feature fairly.
In real life: two pizza places
Both pizza shops average 30 minutes. One always arrives between 28 and 32. The other swings from 10 to 50. Same mean, very different variance, and you know which one you’d trust for a party.
Quick check: Which dataset has the larger variance?
- [4, 5, 6]
- [1, 5, 9] (correct)
- They are equal
Both have mean 5, but [1, 5, 9] sits much farther from it, so its squared distances are bigger.
Pseudocode
data = [2, 4, 4, 4, 5, 5, 7, 9] mean = add them up / how many # 40 / 8 = 5 variance = average of (x − mean)² # 4 std = √variance # 2: the typical distance standardized x = (x − mean) / std # now centered at 0, with a spread of 1
Key terms
- variance
- How spread out numbers are: the average squared distance from the mean.
- standard deviation
- The typical distance from the mean. The square root of variance.
- normal distribution
- The bell-shaped pattern many natural measurements follow.