Lesson 5 of 116 min
Samples, averages and the normal distribution
A score is an average of many draws, so it moves from test to test; averages pile into a bell, and four times the draws make the bell half as wide.
After this lesson you can estimate a quantity from a sample, say why averages form a bell curve, and say how more data helps.
Loading the video…
Refreshers
An idea from an earlier lesson shows up here when the video leans on it.
In real code
What the video left out, as you will meet it in your own code.
Draw a test the old and new ways
You'll still see np.random.binomial in older notebooks. In new code, make a generator with default_rng and keep it with your work. Each draw below counts correct answers out of 100 independent questions, each with an 80% chance of success. The seed makes each cell repeatable.
import numpy as np
np.random.seed(0)
print(np.random.binomial(100, 0.8, size=5) / 100)
rng = np.random.default_rng(0)
print(rng.binomial(100, 0.8, size=5) / 100)[0.8 0.78 0.79 0.8 0.81] [0.79 0.83 0.87 0.88 0.76]
Read the area under the bell
The standard error for an average of independent right-or-wrong scores is sqrt(p * (1 - p) / n). Put that spread into a normal curve. Its cumulative distribution cdf gives the area to the left of a point. Subtract two areas to see how often a score falls between them.
from scipy.stats import norm
p, n = 0.8, 100
se = np.sqrt(p * (1 - p) / n)
bell = norm(loc=p, scale=se)
for k in (1, 2):
area = bell.cdf(p + k * se) - bell.cdf(p - k * se)
print(f"Within {k} × standard error: {area:.1%}")Within 1 × standard error: 68.3% Within 2 × standard error: 95.4%
Average more penguins
Run the same experiment with masses. In each row, draw penguins independently with repeats, then take that row's average. Four times as many penguins makes the averages spread out about half as much.
import pandas as pd
url = "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv"
mass = pd.read_csv(url).body_mass_g.dropna().to_numpy() / 1000
rng = np.random.default_rng(0)
for size in (10, 40):
averages = rng.choice(mass, size=(10_000, size)).mean(axis=1)
print(f"{size} penguins: spread {averages.std():.3f} kg")10 penguins: spread 0.250 kg 40 penguins: spread 0.126 kg
Count passages as groups
Questions on one passage can move together. In this toy test, each passage has four questions that always share a score. A hundred questions now give you only 25 independent draws. In Miller's DROP example, the grouped standard error was about three times the one that treated questions as independent.
rng = np.random.default_rng(0)
for draws in (100, 25):
scores = rng.binomial(draws, 0.8, size=10_000) / draws
print(f"{draws} independent draws: spread {scores.std():.1%}")100 independent draws: spread 4.0% 25 independent draws: spread 8.0%
Run on Python 3.13.3, NumPy 2.5.5, pandas 3.1.1 and SciPy 1.18.1. Checked on .
Quiz
Two questions on this lesson, and one from earlier. Answer as often as you like.
1 of 3
From earlier: Expectation and variance
Five penguins weigh 3, 3, 3, 4 and 7 kilos. You give one guess for all five. Each guess is scored like a model: square every miss, then average. Which guess gets the smallest loss?
2 of 3
A model gets 8 questions in 10 right. You give it five new tests of 100 questions, all just as hard. What will its five scores look like?
3 of 3
A model gets 9 questions in 10 right, so one question's standard deviation is 0.3. On a test of 100 questions, what is the standard error of its score, in points?
The ideas in this lesson
- Normal distribution
- The bell: most values near the centre, fewer and fewer farther out, the same on both sides.
- Central limit theorem
- Averages of many independent draws pile into a bell, whatever one draw looks like.
- Standard error
- How far an average moves: one draw's standard deviation divided by the square root of the count.
It leans on
Transcript
What the video says, part by part. Press a time to watch from there.
Will the score move?
Here's a bet. A model takes a test, and it gets a score. Now give it a new test, just as hard.
Will it get the same score? And if it doesn't, how far could the score move?
Your guess
Say the model gets eight questions in ten right. Give it a test of a hundred questions. Will it score eighty percent every time? Within a point or two?
Or often four points away, or more?
A score is an average
Start with what a score is. Each question scores one if the model gets it right, and zero if it gets it wrong. The score is the average. Eighty right out of a hundred is zero point eight: eighty percent.
One question alone is two bars. Zero, with a chance of zero point two, and one, with a chance of zero point eight.
Its expected value is zero point eight. Its standard deviation is zero point four. For a right-or-wrong question, that's the square root of zero point eight times zero point two. Two bars, and nothing like a bell.
A test is a draw
Each answer is a draw: right with a chance of zero point eight.
So a test of a hundred questions is a hundred draws, and its score is a draw too.
Here are five new tests.
Eighty-one.
Seventy.
Eighty-four.
And two more near eighty.
Five different scores.
Only about one test in ten lands on exactly eighty.
So a score is a guess at the model's true eighty percent, made from a hundred draws.
And it moves.
The bell
Now take a thousand tests. Where do the scores land?
The scores pile up near eighty. Fewer and fewer land far from it, the same on both sides. Most are within about four points: from seventy-six to eighty-four percent.
Ninety-five tests in a hundred land within eight points. That's between seventy-two and eighty-eight. If you said a point or two, here's why that seemed likely: the model didn't change. But each test is a new set of draws.
This shape... is called the normal distribution. The bell.
Why a bell
But why a bell, when one question is only two bars?
Watch the tests grow. Tests of one question: two bars. Tests of ten questions: eleven bars, leaning to one side. Tests of a hundred: the bell.
What would it take to score fifty percent on a hundred questions?
It would take fifty wrong answers. The model gets about twenty.
And each answer is right or wrong by itself, so thirty extra wrong answers in one test is rare. Most mixes of right and wrong land near eighty.
Whatever one draw looks like
Does the bell only come because each answer is right or wrong?
Here are the masses of the penguins from Python for AI. They're not a bell: the light Adelies and Chinstraps, and the heavy Gentoos.
Will averages of ten penguins be a bell?
Pick ten penguins at random, and average their masses. Do it a thousand times.
A bell, around four point two kilos.
Averages of many independent draws pile into a bell, whatever one draw looks like. That's called the central limit theorem.
More questions
So how do you make a score move less?
Use more questions. Make the test four times as long: four hundred questions.
How much narrower is the bell now? A quarter as wide?
No. Half as wide. About two points, not one.
The standard error
The bell's spread is called the standard error.
It's one question's standard deviation, zero point four, divided by the square root of the number of questions.
At a hundred questions, that's zero point four divided by ten: zero point zero four, or four points.
At four hundred, zero point four divided by twenty: two points.
And ninety-five tests in a hundred land within two standard errors.
At a hundred questions, that's the eight points you saw. At four hundred? Four points: from seventy-six to eighty-four.
So four times the questions only halves the spread. More data helps, but slowly.
In code
Now in real code.
NumPy runs ten thousand tests of a hundred questions in one line. It counts the right answers in each test, then divides by a hundred. Then we print the first five scores, and the spread of all ten thousand. What will the spread be?
Zero point zero four: four points, as the bell showed. At four hundred questions: zero point zero two.
And one line works it out with no random draws at all: zero point zero four again. So put this number beside a score. Researchers at Anthropic say every test of an AI model should report it.
Every score, a bell
So a score is an average of draws, and it moves from test to test. Averages of many draws pile into a bell, the normal distribution.
And its spread, the standard error, gets smaller with the square root of the number of draws.
Every score lands on a bell
Every score is an average, and averages land on a bell. Now try it on this lesson's page, and take the quiz. Find out how many questions make a score move one point.
You use this lesson in Lab 2: Scan the penguins before a model, after Correlation.
Facts last checked on .
