learn-ml-epistemology-with-phoebe / Practitioner session 6 of 10
Learn ML Epistemology with Phoebe · Practitioner session 6 of 10

How big does a test set need to be

Session 5 left one lever unmeasured. Hold the candidate count at 60 and change only the number of rows the test set has, and the optimism runs 0.0091 at 200 rows and 0.0030 at 2000. The trend is clean from 200 upward and well outside the error bars. At 100 rows something more interesting happens: the estimate reads 0.0071 with a standard error of 0.0030, which means it cannot be ranked against the 200-row estimate at all. At that size the measurement of the bias is itself too noisy to trust.

🔴 Hardest Anyone deciding how to split their rows Anyone about to claim a small margin 45 min
0-3 · Welcome 3-17 · The interval around a score 17-31 · The size sweep, measured 31-45 · Build-along and Q&A
Part 0

Where tonight sits

Session 5 showed that selecting on a set inflates the number it reports, and named two things the gap grows with: how many candidates were compared, and how noisy each measurement was. Tonight is the second one, because it is the one under your control at the moment you split the data. A test set has two jobs, estimating an accuracy and ranking things against each other, and a small one fails at both in ways that reinforce each other.

Live = written together in the 45 minutes Self-study = the full depth, after class 🔍 Every diagram zooms

★ What you walk out with tonight. The size sweep with its error bars, so you know the shape of the relationship rather than a rule of thumb. A working method for turning a claimed difference into the number of rows it needs, which takes about four lines. The reason a 0.4 point margin is not a finding on a small set. And the observation at n = 100 that is worth more than the rest of the table: an estimate that cannot even rank itself.

LiveTwo jobs, and a small set fails at both4 min▶

The first job is estimation. A test set answers "roughly how accurate is this model", and the answer arrives with a width around it that comes from having counted a finite number of patients. Nobody disputes this and almost nobody reports it.

The second job is ranking. A test set answers "is this model better than that one", and that question is harder, because it needs the width around the difference rather than the width around either number. A set that gives a usable answer to the first question can be useless for the second.

Session 5 added a third thing a small set does, which is not a failure of the set so much as a consequence of it: selection takes the maximum of noisy measurements, and a noisier measurement gives selection more to work with. The three compound.

Self-studyThe words that will keep coming back4 min▶
  • Standard error. The typical distance between an estimate and the thing it estimates, from having counted a finite sample rather than the whole world.
  • Interval. The band around an estimate that is consistent with what was counted. Reporting the point and not the band is the normal practice and the normal mistake.
  • The square-root law. The noise on an estimate falls with the square root of the row count, so halving it costs four times the rows.
  • Ranking against estimating. Two different jobs with two different size requirements. Ranking always needs more.
  • The compounding. A noisier estimate widens the interval and enlarges the selection optimism at the same time. Session 5 measured the second effect at a fixed size; tonight moves the size.
  • Precision against validity. A bigger set narrows the interval around today's accuracy and says nothing about whether tomorrow resembles today. Session 1 owns that distinction and it does not go away tonight.
Part 1 · covers the size sweep

The same bias, measured at five sizes

12 min live

Candidate count fixed at 60, forty replications per row, and the only thing changing is how many patients the test set holds. The bars are the error bars on the measurement of the bias itself, which is the part of this table that does the most teaching.

The same bias, measured on five test-set sizes. k = 60, mean of 40 replications. Bars run plus and minus one standard error of the mean. n = 100 0.0071, se 0.0030 n = 200 0.0091, se 0.0022 n = 400 0.0062, se 0.0017 n = 1000 0.0044, se 0.0010 n = 2000 0.0030, se 0.0006 optimism 0 0.0025 0.0050 0.0075 0.0100 0.0125 From 200 upward the trend is clean and well outside the error bars. At n = 100 the estimate is 0.0071 with a standard error of 0.0030, and it cannot be ranked against n = 200. At very small test sets even the measurement of the bias is too noisy to trust.
🔍 Click to zoom - four rows form a clean trend and the fifth one demonstrates the problem instead of describing it.
Test nOptimismSE
1000.00710.0030
2000.00910.0022
4000.00620.0017
10000.00440.0010
20000.00300.0006
LiveThe row that teaches the most is the one that misbehaves4 min▶

Read the table from 2000 upwards and it is tidy: 0.0030, 0.0044, 0.0062, 0.0091, with error bars small enough that the ordering is not in question. A bigger test set buys back the optimism, cleanly and monotonically. Then the last row breaks the pattern, and it breaks it downwards, reading 0.0071 where the trend wanted something larger than 0.0091.

The standard error is what to look at, not the point. At n = 100 it is 0.0030, the largest in the table, and wide enough that the estimate overlaps the one at n = 200. The honest statement is that these two rows cannot be ranked against each other. That is not a defect in the bench; it is the subject of the session arriving one level up. At 100 rows the measurement of the bias is as unreliable as the accuracies the bias was measured from, and a run that reported only the point estimate would have produced an apparently interesting reversal out of nothing.

Self-studyWhy halving the noise costs four times the rows3 min▶

An accuracy is a proportion counted over independent rows, and the noise on a counted proportion falls with the square root of the row count rather than with the row count itself. Going from 500 rows to 1000 does not halve the width of the interval; it shrinks it by about a third. Halving the width needs four times the rows, and quartering it needs sixteen times.

That is why the answer to "should we grow the test set" is so often no in practice and yes in principle. The next increment of precision is always more expensive than the last one, and the returns are visible in the SE column: 0.0030, 0.0022, 0.0017, 0.0010, 0.0006 while the row count goes up twentyfold.

Part 2 · covers the small-margin claim

Beating them by 0.4 points is not a finding

10 min live

The most common claim in a model review is a small margin over an incumbent. It is also the claim most likely to be manufactured by the process that produced it, because a margin of that size is exactly what selection alone buys.

A gap of 0.4 accuracy points has at least three possible authors. 1 · Selection Best of 100 candidates reports 0.9569. Best of 1 reports 0.9527. The gap is 0.0042, and real accuracy moved -0.0003 over the same sweep. 2 · Test-set noise A small set measures anything imprecisely. At n = 100 even a mean over 40 replications carries a standard error of 0.0030 on the bias alone. 3 · A better model Sometimes this is the answer, and it is the one everybody assumes. Nothing in a single reported number separates it from the other two. A difference the size of the selection effect is not evidence of a better model. Report the test-set size and the number of candidates beside the score, or the reader cannot tell which author they are reading.
🔍 Click to zoom - the third author is the only one anybody names, and it is the one the number cannot establish.
LiveWhy the difference is noisier than either number4 min▶

Two accuracies measured on independent test sets each carry their own noise, and the difference between them carries both. That is the geometry people skip: a margin needs more rows than a point estimate does, not fewer, even though a margin feels like a smaller quantity.

The one saving grace is that scoring both models on the same rows removes part of the problem, because patients that are hard for one model are often hard for the other and that shared difficulty cancels out of the difference. It is a real and worthwhile gain, and it is also the reason the same set then ends up arbitrating every comparison anybody makes, which is session 5's problem returning by the back door.

LiveWorking backwards to the number of rows4 min▶

Start from the decision rather than from the data. Name the smallest difference that would change what anybody does. If a two-point improvement is the threshold for replacing an incumbent, then a set sized to resolve two points is enough and a set sized to resolve a tenth of a point is a waste of rows that would have trained a better model. If the decision genuinely turns on a tenth of a point, the square-root law says what that costs and the honest answer is often that the data does not exist.

Doing this in advance has a second effect that matters more than the arithmetic. A team that wrote down "we need to see at least two points" before the run cannot later be impressed by half a point, which is the failure mode this whole track is built around.

Working backwards from the difference you want to defend. 1 · The gap The difference you want to call real, in accuracy points, set by the decision. 2 · The noise The standard error of one accuracy estimate on a test set of size n. 3 · The pair Two estimates, so the noise on the difference is larger than on either one. 4 · The size Raise n until the noise on the difference is small against the gap. The noise shrinks as the square root of n. Halving it costs four times the rows. A difference between two estimates is noisier than either estimate, so a gap needs more rows than a single number does.
🔍 Click to zoom - the first box is a decision, not a statistic, and it is the one teams skip.
Part 3 · covers the compounding

A small test set is dangerous twice

6 min live

The two failures are not independent problems that happen to co-occur. They have the same cause, which is why the row count is a better lever than anything downstream of it.

A small test set carries two costs at once. 1 · The estimate is wide Any accuracy computed on few rows is imprecise, and a difference smaller than the imprecision cannot be read at all. 2 · The selection bias is larger Optimism runs 0.0091 at n = 200 down to 0.0030 at n = 2000. A noisier estimate gives selection more noise to maximise. One shortage produces both, which is why test-set size is the lever. The candidate count is the thing people argue about; the row count is the thing that moves.
🔍 Click to zoom - same cause, two symptoms, and only one of them gets discussed in a review.
Where the rows should go, unresolved. Spend them on the test set A wider training set buys a slightly better model. A wider test set buys the ability to tell whether it is better at all. Spend them on training On a small problem the model is the binding constraint. An interval you cannot narrow is worth less than a model you can improve. Both sides are arguing about the same rows, and neither has a general answer. What settles it locally is the size of the difference the decision actually turns on.
🔍 Click to zoom - a live disagreement worth naming in the room rather than settling with a default ratio.
Part 4 · build-along

Run the size sweep, then size your own set

14 min build-along

Two blocks against the engine on this page. The first reproduces the size sweep including its error bars, which is the only way the n = 100 row means anything. The second turns a claimed difference into a row count.

Open the console on this page. ep-live.js is loaded here, so window.THORNBURY already exists with the generator and the selection helpers on it.

Run the sweep with the error bars in it. A mean over replications without its standard error is what produced the apparent reversal at n = 100. Compute both or compute neither.

Check the two rows that overlap. Print the interval at n = 100 and at n = 200 and satisfy yourself that they cannot be ranked.

Measure the noise on a single accuracy. One model, five test-set sizes, the standard error at each. Watch it fall with the square root rather than with the row count.

Size a set from a claimed difference. Feed the smallest margin your team would act on into the last function and see the row count it asks for.

Compare it with the set you actually have. If the required count is larger than the rows in hand, the margin was never measurable and the honest report says so instead of quoting it.

★ Block 1 · the size sweep, with the standard error that makes it readable /* ep-live.js is loaded on this page and exposes window.THORNBURY */ const T = window.THORNBURY; const train = T.makeData(3000, 77, 0.90); const fresh = T.makeData(6000, 88, 0.90); /* nobody selects on these */ function optimismAt(n, k, reps) { const gaps = []; for (let r = 0; r < reps; r++) { const test = T.makeData(n, 5000 + r * 13, 0.90); const pool = T.candidatePool(train, k, 20000 + r * 500); const s = T.selectOnTest(pool, test, fresh); gaps.push(s.reported - s.honest); } const mean = gaps.reduce((a, b) => a + b, 0) / reps; const sq = gaps.reduce((a, b) => a + (b - mean) * (b - mean), 0) / (reps - 1); return { mean: mean, se: Math.sqrt(sq / reps) }; } for (const n of [100, 200, 400, 1000, 2000]) { const o = optimismAt(n, 60, 40); console.log(n, o.mean.toFixed(4), o.se.toFixed(4)); } /* 200 0.0091 0.0022 2000 0.0030 0.0006 The 100 row reads 0.0071 with an se of 0.0030 and overlaps the 200 row. Print the se or the reversal looks like a result. */
★ Block 2 · the interval around one score, and the rows a margin needs const T = window.THORNBURY; const train = T.makeData(4000, 101, 0.90); const model = T.train(train, 1); /* 12 tanh units, 30 epochs */ /* the width around a single accuracy: a proportion counted on n rows */ function seOfAccuracy(model, rows) { const p = T.acc(model, rows); return Math.sqrt(p * (1 - p) / rows.length); } for (const n of [100, 200, 400, 1000, 2000]) { const test = T.makeData(n, 6100 + n, 0.90); console.log(n, T.acc(model, test).toFixed(4), seOfAccuracy(model, test).toFixed(4)); } /* the rows a claimed margin needs. Two independent estimates, so the noise on the difference is larger than the noise on either one of them. */ const big = T.makeData(2000, 6200, 0.90); const p = T.acc(model, big); function rowsNeeded(gap, p, z) { return Math.ceil(2 * z * z * p * (1 - p) / (gap * gap)); } console.log(rowsNeeded(0.004, p, 2)); /* rows to defend a four-thousandth margin */ console.log(rowsNeeded(0.020, p, 2)); /* rows to defend a two-point margin */ /* Run it before you trust it. The point of the two calls is the ratio between them: a quarter of the margin costs sixteen times the rows. */

The habit to keep. Two numbers belong next to every reported accuracy, and they cost one line: the number of rows it was counted on, and the number of candidates that were compared on those rows. With both, a reader can work out roughly how much of the score to believe. With neither, the score is a point estimate of unknown precision selected by an unknown amount of search, and no amount of decimal places fixes that.

Check yourself

Three questions

The measured optimism reads 0.0091 at n = 200 and 0.0071 at n = 100, which breaks the trend. What is the right reading?

The standard error at n = 100 is the largest in the table and wide enough that the two rows overlap. Reading the point estimates alone would turn noise into a reversal, which is the same error the rest of the sweep is warning about, arriving one level up.

A team reports that their model beats the incumbent by 0.4 accuracy points, after keeping the best of 60 configurations on a test set of 200 rows. What can be concluded?

Selecting the best of 100 candidates moved reported accuracy by 0.0042 while real accuracy moved -0.0003, so a margin of that magnitude is exactly what a search of that size manufactures. At 200 rows the optimism was measured at 0.0091, which is larger than the claimed margin.

Doubling a test set from 500 rows to 1000 does what to the width of the interval around the accuracy?

An accuracy is a proportion counted over rows and its noise falls with the square root of the count. Halving the width needs four times the rows and quartering it needs sixteen times, which is why the next increment of precision always costs more than the last one.

Homework

Before session 7

30 min

Take the score you reconstructed for session 5 and finish the job: write down the row count of the set it was measured on, the candidate count that was compared on it, and the smallest difference your team would act on. Then run block 2 and see whether the set you have can resolve the difference you care about. Bring one sentence saying either what margin your current set can defend, or how many rows you would need to defend the one you have been quoting. Session 7 moves to numbers somebody else produced, where you will not be able to ask any of these questions.

Sources covered

What tonight maps to

✓ The size sweep with error bars k = 60 and a mean of 40 replications: optimism 0.0071, 0.0091, 0.0062, 0.0044 and 0.0030 at n of 100, 200, 400, 1000 and 2000, with standard errors 0.0030, 0.0022, 0.0017, 0.0010 and 0.0006.
✓ The n = 100 row The estimate is 0.0071 with a standard error of 0.0030 and cannot be ranked against n = 200. At very small test sets even the measurement of the bias is too noisy to trust.
✓ The interval around an accuracy Why the point estimate is not the finding, why the noise falls with the square root of the row count, and why a difference is noisier than either number in it.
✓ Sizing a set from a claimed difference Start from the smallest margin that would change a decision, then work back to the rows. Computed live in block 2 rather than quoted.
✓ The compounding with session 5 A noisier estimate widens the interval and enlarges the selection optimism from the same shortage of rows, which is why the row count is the lever.
✓ Where the rows should go A live disagreement between spending a fixed row budget on training and spending it on the test set, named rather than settled with a default ratio.
◐ What a benchmark licenses Session 7. Construct validity and the benchmark lottery, for numbers somebody else produced on a set you cannot size.
· Precision against validity Owned by session 1. A bigger test set narrows the interval around today's accuracy and says nothing about whether tomorrow resembles today.
· Metric definitions and drift detection Not covered by design. learn-model-evaluation-with-phoebe defines every metric and owns monitoring.

Session 6 cheat sheet

0.0091 at 200, 0.0030 at 2000A bigger test set buys back the optimism, cleanly from 200 upward.
n = 100 cannot rank itself0.0071 with a standard error of 0.0030. The measurement of the bias is as noisy as the thing it measures.
Print the standard errorWithout it the n = 100 row looks like a reversal instead of a warning.
The square-root lawHalving the noise costs four times the rows. Quartering it costs sixteen times.
A margin needs more rowsTwo estimates carry two lots of noise, so the difference is noisier than either one.
Start from the decisionThe smallest difference anybody would act on sets the size, not a default ratio.
Dangerous twiceOne shortage of rows widens the interval and enlarges the selection optimism together.
Two numbers beside the scoreRows counted and candidates compared. Without both, a reader cannot discount anything.