Course / Tutorials / Week 2 / CS-2
Case study CS-2 · Week 2 · about 50 min · Foundation
A step test and a first straight line
Turn a partner's step-test sheet into heart rate and lifting power, fit heart rate against workload, test the line on a stage it has not seen against a mean baseline, and read off a heart rate for easy sessions.
- 1Gather (used)
- 2Statistics (used)
- 3Visualize (used)
- 4Cleanse
- 5Features
- 6Balance
- 7Scale
- 8Split (used)
- 9Deploy
- Ask
- Collect (this week)
- Check (this week)
- Interpret (this week)
- Coach (this week)
- Reassess
Download notebook ·Python file ·Read as Markdown ·Data folder ·Chapter 2 (sections 2.4, 2.11, 2.12, 7.4)
Every cell runs in this page; the first run downloads Python (about 30 s). Nothing you load leaves your browser. Helpful first: Q-4 Type a small table and plot it, Q-5 Fit a straight line and read the slope's units, Q-6 A first-order response: heart rate after a step.
The decision
Sam wants one number to keep easy sessions easy: a heart rate to stay under. A step test with a talk test gives it, if the line through the counts can be trusted on a workload it was not fitted to. If the line missed held-out stages by 10 beats a minute, no single number would be worth giving.
Before any code: by how many beats a minute will Sam's heart rate rise from the first stage (15 step cycles a minute) to the fifth (35), and will a straight line predict a held-out stage to within 5 beats a minute?
The raw data
raw/steptest_five_stages_synthetic.csv: a partner's step-test sheet, SYNTHETIC; a 30 s resting count and five 3-minute stages on a 0.30 m bench, with the metronome setting, the beats counted, the length of each count and the talk-test answer. Made by this tutorial'sprepare.pyfrom the same model as the book's step test (Chapter 2, Sections 2.4 and 2.11); a made-up 70 kg student, not a real person.
| Field | Meaning | Unit | Range | Missing |
|---|---|---|---|---|
stage | rest or stage 1–5 | text | rest; stage 1 … stage 5 | none |
metronome_bpm | metronome setting; four beats per step cycle | beats/min | 0–140 | 0 at rest |
count_s | length of the pulse count | s | 15 or 30 | none |
beats | beats counted in that time | beats | 20–40 | none |
talk | talk-test answer at the end of the stage: could the athlete speak comfortably? | yes, yes but, no | — | empty at rest |
Nothing is wrong with the numbers, but none is in the unit you need. The metronome is in beats a minute, not step cycles; the counts have two different lengths; and heart rate is not on the sheet at all. The counts also start two seconds after each stage ends, so every one reads a little lower than the heart rate during the stage, more at the harder stages. The file is synthetic, so the true heart rate is known: at the fifth stage it was 155 at the moment Sam stopped, and the count gave 140.
Step by step
Step 1 · Gather: the partner's sheet
Sam (a made-up student; every number here is synthetic, made by prepare.py from the same model as the book's step test in Section 2.11) stepped on a 0.30 m bench for five 3-minute stages, each faster than the last. Sam weighs 70 kg. After each stage a partner counted beats for 15 seconds, starting two seconds after Sam stopped, and asked Sam to read a short paragraph aloud: could Sam speak comfortably? (the talk test, Section 7.4.4). Before the test the partner also counted 30 seconds at rest. The file is the sheet as the partner wrote it.
Type a prediction to enable Run.
Show the expected result without running
stage metronome_bpm count_s beats talk rest 0 30 33 NaN stage 1 60 15 25 yes stage 2 80 15 27 yes stage 3 100 15 31 yes stage 4 120 15 33 yes but stage 5 140 15 35 no
Two things on the sheet are not yet the numbers you need. The metronome is set in beats a minute, four beats per step cycle (up, up, down, down), so 60 on the metronome is 15 cycles a minute. And the counts are not all the same length: 30 seconds at rest, 15 after each stage. Turn each into the quantity it stands for, with the unit in the column name, and keep the sheet untouched.
Show the expected result without running
stage rate_cpm power_W hr_bpm talk rest 0.0 0.0 66.0 NaN stage 1 15.0 51.5 100.0 yes stage 2 20.0 68.7 108.0 yes stage 3 25.0 85.8 124.0 yes stage 4 30.0 103.0 132.0 yes but stage 5 35.0 120.2 140.0 no
Step 2 · Statistics: what can these counts resolve?
A profile before any fit. How far does heart rate move across the test, and what is the smallest step a count can show?
Type a prediction to enable Run.
Show the expected result without running
rest: 66 bpm (30 s count) stages: 100 to 140 bpm over 51.5 to 120.2 W resolution of a 15 s count: 60/15 = 4 bpm; of the 30 s rest count: 2 bpm rise per stage (bpm): [8, 16, 8, 8]
Heart rate rises by 40 beats a minute across the five stages, in steps of 8, 16, 8 and 8. Each count can only move in steps of 4, and a partner can miscount by a beat, so a single stage can be 4 beats a minute off either way. That is the size of error the fit must be judged against.
Step 3 · Visualize
Show the expected result without running

The five stages lie close to a straight line. Rest, at 66, happens to sit near where that line would meet zero watts, but nothing guarantees it: in Q-5's three-stage test the line met zero watts 11 beats a minute below rest. A line is only tested over the range of its data. Sam could talk comfortably through the first three stages, only just at the fourth, not at the fifth.
Step 8 · Split: fit the line, then test it on a stage it has not seen
A line through five points always looks good on the points it was fitted to. The honest test is a point it has not seen. Hold out one stage, fit the line to the other four, predict the held-out stage, and repeat for each stage in turn. Compare with the mean baseline: ignore power and always guess the average heart rate of the four training stages. A line that cannot beat that has learned nothing (Section 2.11, the engineer's note "Your first straight-line fit").
Type a prediction to enable Run.
Show the expected result without running
all five: HR = 68.8 bpm + 0.606 bpm/W x P (R² 0.982); 2.08 bpm per cycle/min held out measured line line miss baseline miss stage 1 100.0 100.0 -0.0 -26.0 stage 2 108.0 111.5 -3.5 -16.0 stage 3 124.0 120.0 4.0 4.0 stage 4 132.0 130.8 1.2 14.0 stage 5 140.0 144.0 -4.0 24.0 mean absolute miss: line 2.5 bpm, baseline 16.8 bpm
Fitted to all five stages, each watt adds 0.61 beats a minute, or 2.1 per extra step cycle a minute. On stages it had not seen, the line misses by 2.5 beats a minute on average, against 16.8 for the mean baseline: it has learned something real. Its misses are about one count's resolution, 4 beats a minute, so the line is about as good as the counts allow, even at the fifth stage, where it had to extrapolate beyond the four it was fitted to. The baseline misses the two end stages by the most, 26 and 24 beats a minute, because they are farthest from the average.
Show the expected result without running

A heart rate for an easy session
The talk test gives the decision a boundary. Sam could still talk comfortably at the third stage and not quite at the fourth. Section 7.4.4 reports that the last comfortable stage of a talk test falls close to the first threshold, the top of the easy range. So read the line at the third stage's power, and use the held-out misses as the band.
Show the expected result without running
last 'yes' stage: stage 3, 25 cycles/min, 85.8 W line: 121 bpm, held-out band ±4 bpm -> easy up to about 121 bpm counts start 2 s after stopping, so a strap read while moving shows more (Section 2.12)
The line puts the top of Sam's easy range at about 121 beats a minute, give or take 4. That number comes from counts taken after Sam stopped, and heart rate starts falling the moment work stops; Section 2.12 measured that effect at about 9 beats a minute for the book's version of this test. A strap read while moving will therefore show somewhat more at the same effort. Say so on the action card, and retest with the same bench, the same metronome and the same partner.
How good is the number?
Three checks. Held-out error: fitted to four stages and tested on the fifth, the line misses by 2.5 beats a minute on average and at most 4, the resolution of a 15-second count; the mean baseline misses by 16.8. Resolution: the counts move in steps of 4, and a partner may miss a beat, so no stage is known to better than about ±4. Bias: counts start after the athlete stops, so they read low, by about 9 beats a minute at the book's last stage (Section 2.12) and more at higher heart rates. Five points also cannot show whether the true relation bends near the top of the range.
Action card
- Finding
- Your easy range tops out at about 121 beats a minute, measured by a 15-second count right after stopping.
- Evidence
- A straight line through five stages (0.61 beats a minute per watt) predicted each held-out stage to within 4 beats a minute; you could still talk comfortably at the third stage, where the line reads 121.
- How sure
- Moderate. Counts are ±4 beats a minute, and they read low because heart rate falls as soon as you stop; a strap worn while moving will show several beats more.
- Action
- Keep easy sessions at a pace where you can still talk comfortably and your heart rate stays at or under about 121 by a quick count (roughly 130 on a strap, which reads about 9 beats a minute above a count). This is training information, not medical advice.
- Test again
- Repeat the same test, same bench, metronome and partner, in six weeks; a lower heart rate at the same stage means the same work costs your heart less.
Track it
Add one row per stage: test=step-test, metric=hr_stage3_bpm (and stages 1–5), value, unit=bpm, protocol_version=v1-bench30-15s-count, plus one row for the slope: metric=hr_slope_bpm_per_w, unit=bpm/W. The slope and the heart rate at a fixed stage are the two numbers to compare at the next battery.
With your own data
Replace the sheet with your own counts and change MASS and BENCH in the Step 1 cell. Keep the talk test the same every time. Heart rate is a personal health number: it is never graded or shared without your consent.
Check the AI
Asked to "fit the step test and tell Sam how good the fit is", an assistant replied:
> The line HR = 68.8 + 0.606 × P fits the five stages with R² = 0.98, so it predicts Sam's heart > rate to within about 2%. At 30 cycles a minute Sam's heart rate is 0.606 × 30 + 68.8 = 87 bpm.
What is wrong with it?
The prediction puts step cycles (30) into a slope that is in beats a minute per watt. Thirty cycles a minute is 103 W, which gives about 131 beats a minute; 87 is lower than the first stage. The R² is real, but it is measured on the points the line was fitted to; the honest number is the held-out miss of about 2.5 beats a minute, and the counts read low because they start after Sam stops.
Check yourself
Why compare the line with a mean baseline?
Why does the mean baseline miss the first and fifth stages by the most?
The slope is 0.606 bpm per watt. With a 70 kg athlete on a 0.30 m bench, one more step cycle a minute adds 3.43 W. How many bpm is that?
The counts start two seconds after each stage. In which direction does that push the easy-session heart rate?
Challenge: Your own step test, against a strap
Run the step test of Chapter 2's field exercise yourself, with a partner, the talk test at each stage, and, if you have one, a chest strap or a watch recording at the same time. Use the book's strap record of Sam's test (book/ch02-system/data/steptest_hr.csv, synthetic) if you have no strap.
- Type your sheet in the same format and convert it with the Step 1 cell; record your mass and bench height.
- Fit heart rate against lifting power and give the slope in bpm per watt and per step cycle a minute.
- Hold out each stage in turn and report the line's and the baseline's mean absolute miss.
- Take the strap's heart rate over the last 30 s of each stage and fit the same line; compare the slopes and intercepts.
- Read off your easy-session heart rate from the last comfortable talk-test stage, by count and by strap.
Hand in
- the notebook with its outputs
- a table of held-out misses, line against baseline
- an action card with both easy-session numbers and their band
How it is judged
- Units converted and stated in column names (20%)
- Held-out test and baseline done correctly (35%)
- Count against strap compared and the bias explained (25%)
- Action card worded as training information, with a retest (20%)
Hints
The solution unlocks after you make an attempt. Comparing your own attempt with it is where the learning happens.
The same method in another field
Fitting a line on most of the data and testing it on the point left out is how a sensor calibration is checked in a plant: calibrate a thermocouple at four reference temperatures, test it at the fifth. The Machine Learning for Engineers page on splitting data shows the same idea with more data.
Acknowledgements
The model of the synthetic test is the book's (Chapter 2, code/make_synthetic.py); this five-stage version is made by prepare.py in this tutorial's folder.
References
- Data-Driven Athletics, Chapter 2: The Response to a Step (Section 2.4), Measuring Yourself: A Step Test (Section 2.11), How Good Is the Number? (Section 2.12); Chapter 7, Thresholds without blood (Section 7.4.4).
Built 2026-11-30 with Python packages numpy 2.5.5, pandas 3.1.1, matplotlib 3.11.2. In the browser the same code runs on Pyodide, so the last digit can differ.