apopt.comCBE 493R Data-Driven Athletics

Course / Tutorials / Week 11 / Q-32

Quick tutorial Q-32 · Week 11 · about 15 min · Core

Split by athlete, not by row

Score one nearest-neighbor model of peak foot force twice, with shuffled steps and with whole runners held out by fixed folds, and see where the difference comes from.

  1. 1Gather
  2. 2Statistics
  3. 3Visualize
  4. 4Cleanse
  5. 5Features
  6. 6Balance
  7. 7Scale
  8. 8Split (used)
  9. 9Deploy
  1. Ask
  2. Collect
  3. Check
  4. Interpret (this week)
  5. Coach
  6. Reassess

Every cell runs in this page; the first run downloads Python (about 30 s). Nothing you load leaves your browser. Helpful first: Q-31 Scale two features, the right way and the wrong way.

The decision

Before a model's score goes into a report for a coach, decide what it will be used on. For a runner the model has never seen, only a split that keeps each runner on one side gives the honest score.

The raw data

Try it

The file holds about 2,600 left-foot steps from an instrumented treadmill. Each runner contributes many steps, and neighboring steps of one runner are nearly copies of each other. A model tested on steps from runners it has already seen will look far better than it will be for a new runner. The fix is to split by athlete: every step of a runner goes to the same side.

Open the file and label the runners

The file names no runner. Each runner ran a ladder of rising speeds, so a speed the ladder has already used starts a new runner (the same inference as CS-13).

PythonSteps, trials and inferred runners

Type a prediction to enable Run.

Show the expected result without running
2568 steps, 102 trials, 17 runners
median steps per runner: 125

Two splits, one model

The model is five nearest neighbors on the nine gait measures, scaled inside a pipeline. The row split shuffles the steps into five folds. The athlete split makes the fold from the runner number: runner 1, 6, 11 and 16 in one fold, and so on (runner % 5). Fixed folds give the same answer in every version of scikit-learn; GroupKFold does the same job, but how it assigns runners to folds has changed between versions.

PythonShuffled rows against whole runners held out

Type a prediction to enable Run.

Show the expected result without running
split by row     R² 0.93
split by runner  R² 0.31
runners in fold 1: [1, 6, 11, 16]

Where the difference comes from

Compare the error for each runner under the two splits.

PythonError for each runner, two ways

Show the expected result without running
by row       0.06
by runner    0.22
runners whose error grew more than threefold: 10
For each of 17 runners, the mean error in body weights with a row split (circles, all small) and with the runner held out (squares, mostly several times larger).

With a row split, every runner's own steps sat in the training folds, a few rows away, and the nearest neighbors found them. Held out, the model has to predict a runner it never saw, which is the job a coach would give it. Report the second number.

For the athlete: "A model like this one would get your peak force wrong by about a fifth of your body weight on an average step, so we use it to rank gait measures, not to tell you your force."

Action card

Action card
Finding
The same model scores R² 0.93 on shuffled steps and 0.31 on runners it has not seen.
Evidence
With runners held out by fixed folds, the mean error per step rose from 0.06 to 0.22 body weights.
How sure
Moderate. 17 runners inferred from speed ladders on one treadmill.
Action
Report the score with runners held out, and say how the folds were made.
Test again
Recheck with another assignment of runners to folds (for example (runner + 1) % 5).

Check yourself

  1. Why does runner % 5 make a fair split?

  2. For which use is a split by row acceptable?

0 of 2 answered · 0 right the first time

Acknowledgements

The data set and the original case study are from the Data-Driven Engineering course, with data courtesy of Iain Hunter, BYU Biomechanics.

References

Built 2026-11-30 with Python packages numpy 2.5.5, pandas 3.1.1, matplotlib 3.11.2, sklearn 1.9.1, scipy 1.18.1. In the browser the same code runs on Pyodide, so the last digit can differ.