# Models, Leakage and Honest Small Data

Class 22, Chapter 11: Is the Change Real? Statistics and Machine Learning. 29 slides, about 37.5 minutes.

## 1. Title

Slide up while people sit down. Last class ended with a model that scored a perfect one on its own training data. Today we find out what it scores on a runner it has never seen, and the answer changes how you will test every model in your project.

## 2. Check it by hand: critical speed from two races  (2 min)

Many useful models are fitted to one athlete. The first: plot the distance of two or three hard efforts against their time. The points lie near a line. Its slope is critical speed, the boundary between heavy and severe exercise, and the intercept D prime is a distance the runner can cover above it. [Give them a minute with a calculator, then click.] Two races: eighteen hundred metres over four hundred twenty seconds, four point two eight six metres a second, and D prime one hundred seventy-one metres. A third race barely moves it; it shows whether the points lie on a line at all. Nobody runs an all-out trial for this course; use races you have already run.

## 3. Heart rate against speed  (2 min)

The second individual model needs only steady, easy stages, so it is the one for anyone who would rather not race. Four stages, three to four and a half metres a second, heart rate in the last minute of each. Over the middle of the range it is close to a line: sixty-two point five plus twenty-two point eight times speed. Weeks later the four metre per second stage reads one forty-nine, about five beats under the line. A lower heart rate at the same speed is consistent with better fitness. It is also consistent with a cooler day or a better night's sleep. So the rule of last class applies: judge the five beats against the typical error for that stage.

## 4. A fitness–fatigue model fits the curve, not the constants  (2.5 min)

Banister's model writes performance as a baseline plus fitness minus fatigue, each a decaying memory of past training. The listing simulates an athlete with known constants, a jump test every fourth day, noise of zero point nine centimetres, and fits the model three times. The fitted fitness time constant comes out anywhere from thirty-three to eighty-five days; the truth is forty-two. Yet every fitted curve stays within zero point eight centimetres of the truth, less than the test's own noise. So use the shape for planning a block and a taper, but do not quote the constants as facts about the athlete. The Watch dashboard uses fixed constants, and its load ratio label describes load and nothing more.

## 5. A shallow tree against a line, on runners not seen  (2 min)

Back to the group running data, and the two simplest shapes a model can take. A line, and a decision tree: a short list of yes-or-no questions ending in a leaf. Score both against a baseline that knows nothing, the mean of the training steps, and score them on runners the model has never seen. All three beat the mean, and the line beats both trees. Now one runner, the strongest in the data. Both models are too low throughout, because nothing in the gait says high-force runner. And at the two fastest speeds the tree gives the same three point two one: same leaf. A tree cannot go above its highest leaf. Choose on held-out runners, not on the training fit.

## 6. The confusion table  (2.5 min)

Classification predicts a category: made or missed, walking or running. The result on a test set is a confusion table. Here an app labels a hundred shots. Of forty made, it calls thirty-four made, those are true positives, and six missed. Of sixty missed, it calls forty-eight missed and twelve made. Accuracy is zero point eight two. Sensitivity, also called recall, is how many real positives you caught. Specificity is how many negatives you left alone. Precision is how many of your positive calls were right. On the running data, a fast-step classifier scores zero point nine five on a random split and less with runners held out. And a model that always says slow already gets zero point seven one.

## 7. Moving the threshold trades one mistake for the other  (2.5 min)

A classifier gives a probability, and the rule call it positive above one half is a choice. Here a phone decides whether each five-second window is running. The data are synthetic, and like a real day most windows are walking. At a threshold of zero point two the model catches ninety-six percent of running, but more than a quarter of its running calls are fast jogs. At zero point eight almost every call is right, but it misses forty-four percent. Pick the threshold from the use. Now look at accuracy: it hardly moved. And a model that always says not running scores zero point nine. Always report that baseline, and precision and recall for the class you care about.

## 8. The same models, split two ways  (2.5 min)

[Cover the right-hand bars if you can. Ask for guesses.] The course module scores its models with a random twenty percent of rows held out. Then every runner has steps on both sides of the split. Nearest neighbors explains ninety-two percent of the variance that way. [Click.] Hold out whole runners and it explains twelve. The flexible models fall furthest because they are best at memorizing. The linear model, which cannot memorize much, falls least, and the ranking of the models changes. Leakage is information in training that would not be there in real use. In athlete data the most common leak is the simplest: the same athlete on both sides.

## 9. Why so big a gap, and how to split  (2 min)

Why is the gap so big here? Remember last class: at one speed, runners differ by about one body weight. Forty-four percent of all the variation in peak force is between runners. A model that recognizes the runner gets that for nothing. So choose the split to match the use. For a tool for new athletes, split by athlete. For a personal model, split by time: train on earlier days, test on later. Never split frames or steps at random; neighbors are near copies. And three other leaks: fitting the scaler on all the data, duplicated rows like the two hundred ninety-two we removed, and a feature that gives the answer away, like speed when the label is fast.

## 10. Check the AI: a model that is too good  (2 min)

This is the exact message an assistant is likely to give you this week. The code runs. The number is right for that split. [Ask: what is wrong with the claim, and what one change would you ask for? Take an answer, then click.] The split is by row, so every runner sits on both sides, and the claim about predicting a runner's peak force is a claim about new runners. Ask for a grouped split, GroupKFold by runner. The same kind of model then scores about zero point four. In your log, write what the assistant claimed, what you checked, and what changed.

## 11. Which score belongs in the report?  (2 min)

[Thirty seconds, then hands.] The answer is A. The app will meet athletes it has never seen, so the honest test holds whole athletes out. Frames of one athlete are near copies of each other, so a random split lets the model recognize the athlete. B is the leaked score; more training data does not make a dishonest test honest. C averages an honest number with a dishonest one. D is simply false. And the book's advice for your project report: give both numbers, and say which one an athlete should believe.

## 12. A week is a better unit than a day  (2.5 min)

Most athlete data come in time order. A trend is the slow change you want to see, and a rolling mean estimates it, at the cost of reacting late. Six weeks of simulated morning heart rate: in week six the true level rises four beats. Only three single mornings land above the band; the rolling mean makes the shift plain. Single days are noisy; a week is a better unit for a decision. Second idea: autocorrelation. High mornings follow high mornings, so the samples are not independent, and the effective sample size shrinks. The running residuals have a lag-one correlation of zero point eight one: two thousand six hundred twenty rows carry about as much information as two hundred seventy-eight.

## 13. The instructor's data: a week with no runs  (2 min)

Here is the instructor's own watch file, summed by week. Look at the three empty weeks in April. The file writes them as zero. Were they rest, or a watch left at home, or a run on another device? The file cannot tell you. The book's rule: a week with no recorded runs is missing unless the athlete's log says rest. If you code it as zero, a model learns three rest weeks that may never have happened, and every lag and rolling mean near them is wrong too. The last week has one run because the archive stops there. The fix is a question to the athlete, and a note in the file.

## 14. A forecast has to beat ``same as last week''  (2 min)

A forecast predicts next week from the past. The simplest is same as last week, the persistence baseline, and it is hard to beat. The listing builds a forecast in four steps: sum by week and keep empty weeks missing, use only past values, split by time, and compare with persistence. The regression on lags does not beat it, and neither does the four-week mean. Report that. Now the last line: a centered five-week mean scores fourteen, far better than anything. It cheats. It averages the two weeks after the one it predicts. Any smoother that looks both ways, applied before you make features, leaks the future in the same way.

## 15. What ten athletes can show  (2 min)

Your project will have about ten athletes, or one athlete and ten sessions. With ten athletes the interval of a mean is plus or minus zero point seven two standard deviations. A before-and-after study of ten finds a medium effect only twenty-nine percent of the time. So ten athletes can show a large effect, and each athlete's own change against their typical error. They cannot show a small effect, and they cannot show that an effect is absent: we found no difference usually means we could not have found one. The defense is to decide before you look. Half a page, written before data collection. And report every measure you planned, including the ones that showed nothing.

## 16. How good is the number? Statistics have errors too  (1.5 min)

Every number this chapter produced has its own error. The typical error from five pairs has a ninety percent interval from zero point five eight to two point one one: the true wobble could be twice what we measured. One frame at sixty frames a second on a half-second flight moves the height by about two centimetres, the same size as Harper's gain. The disc app's personal band is built well and still flags about one unchanged throw in eight. A model's score is only as honest as its split. And the runner labels in the running data were inferred, so one runner may be two people. Their direction would not change; the details might.

## 17. ``Your result is within the noise''  (2 min)

The hardest message of the chapter is your result is within the noise. Riley gained half a centimetre: possibly, which means unclear. The poor version is accurate and fails. It uses a p-value the athlete cannot use, it turns we cannot tell yet into no improvement, it gives nothing to do, and it ends on the word error. [Read the better version aloud.] It states the number, gives the noise in the athlete's units, says what is known and what is not, gives one action, and names the retest and why it will be more precise. Words that work: we can't tell yet, the test wobbles about a centimetre, and always end with what happens next.

## 18. Build Lab B-11: a baseline on the device  (2 min)

This week your app learns the athlete. It stores every session on the device and judges a new one against the athlete's own history, with the rule from last class: the noise of one new value against a mean of n is s times root of one plus one over n. Fewer than five sessions: baseline building, grade nothing. Smaller than the smallest worthwhile change: within your usual range. At least the SWC and more than two noise units: clearly higher or lower. Otherwise: possibly, retest. The known answer is on the slide; your test must print all tests pass. A stored history is personal data: key it by a code, give a delete button, nothing leaves the phone.

## 19. Before Class 23  (1.5 min)

Project step twenty-three is due next class. Fit a classifier on your project data or an open data set. Report the confusion table, precision and recall for the class you care about, and the majority-class baseline beside the accuracy. Then write the leakage audit: how you split, why that split matches the use, and what else could leak. The build step, B-eleven, is part of it. Exercise eleven point two zero is Riley's message in a hundred words or fewer. Read the first four sections of Chapter 12 before next class; we start turning your analysis into an app a coach can use.
