apopt.comCBE 493R Data-Driven Athletics

Course / Tutorials / Week 11 / CS-16

Case study CS-16 · Week 11 · about 60 min · Core

Forecast next week, and beat "same as last week"

Turn two and a half years of watch activity summaries into weekly training load from heart rate, build forecasts from the past only, split by time, and test whether a regression really beats the persistence baseline; end with next week's load and a range.

  1. 1Gather (used)
  2. 2Statistics (used)
  3. 3Visualize (used)
  4. 4Cleanse (used)
  5. 5Features (used)
  6. 6Balance
  7. 7Scale
  8. 8Split (used)
  9. 9Deploy
  1. Ask
  2. Collect (this week)
  3. Check (this week)
  4. Interpret (this week)
  5. Coach (this week)
  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-33 A rolling mean and a band.

The decision

A coach plans next week's training and wants to know how much training load this athlete is likely to carry, with a range, before deciding whether to add or remove a session. A forecast is only worth using if it beats "same as last week". This is training information, not medical advice.

Predict first

A regression on last week's load, the week before, and the mean of the last four weeks is tested on the final 52 weeks against "same as last week". Which wins, and by how much?

The raw data

Data dictionary
FieldMeaningUnitRangeMissing
start_timestart of the activityISO 8601 UTC (ends in Z)2024-06-28 to 2026-11-28none
utc_offset_hlocal clock minus UTC at the starth−7 to +3 (mostly −6 and −7)none
sportsport as the watch labels ittextrunning, fitness_equipment, swimming, cycling, hiking, generic, walking, trainingnone
total_timer_timetimer time with pauses excluded (the moving time)s1.83 to 28 676none
total_distancedistancem0 to 21 859blank or 0 on 91 rows, mostly elliptical and indoor bike
avg_heart_rateaverage heart rate (wrist)beats/min67 to 188blank on 6 activities
max_heart_ratehighest heart rate in the activitybeats/min81 to 209blank on 5 activities

What is wrong with it: times are in seconds and distances in meters, and the start is in UTC with the local offset in a separate column (travel moves it from −7 to +3 hours). Four activities last under a minute (aborted starts, one a 0.2-minute "run" with no distance). Six have no average heart rate, so their load cannot be computed as recorded; three of them are real sessions, including a 37-minute run. The highest wrist reading on a run, 209 bpm, is probably the sensor locking onto cadence, so HRmax is taken as the 99th percentile, 202 bpm. The export starts on a Friday, so the first week is partial. Five weeks, all over the December holidays, have nothing recorded; they are kept as zero, which assumes the watch was not simply left at home.

Step by step

A coach planning next week's training wants a number for the load the athlete is likely to carry, with a range. Any forecast has to beat the simplest one there is: same as last week, the persistence baseline (Section 11.8.1). If it cannot, use persistence and say so.

The data are two and a half years of activity summaries from one GPS watch with a wrist heart sensor, worn by an adult male athlete in his mid-40s who mostly runs, and also swims, uses an elliptical, rides and hikes. Load here is the case file's training load: moving minutes times (average heart rate / HRmax) squared, summed over every activity in a week, in arbitrary units (AU). A 50-minute run at 80% of HRmax adds 50 × 0.8² = 32 AU. This is training information, not medical advice.

Step 1 · Gather

The file is the watch's own FIT session summary, one row per activity, in the watch's units: times in seconds, distances in meters, and the start time in UTC with a separate offset to the local clock.

PythonStep 1 · Open the export and put the start on the local clock

Type a prediction to enable Run.

Show the expected result without running
sport
running              497
fitness_equipment     73
swimming              67
cycling               19
hiking                13
generic               13
walking               10
training               1
from 2024-06-28 to 2026-11-28 (126 weeks)
hours from UTC: {-6.0: 465, -7.0: 191, 3.0: 16, -4.0: 14, -5.0: 7}

Most activities are on a clock six or seven hours behind UTC (summer and winter time); the others are travel. Using the offset the watch stored keeps a 6 a.m. run in the right day.

Step 2 · Statistics

Profile the activities before summing anything. Look at the shortest ones, the heart rates the load depends on, and the day of the week.

PythonStep 2 · Profile activities and heart rate

Type a prediction to enable Run.

Show the expected result without running
                   minutes  avg_hr
sport                             
cycling               53.0   129.0
fitness_equipment     50.0   129.0
generic               45.0   140.0
hiking                55.0   110.0
running               48.0   157.0
swimming              55.0   123.0
training              24.0   120.0
walking               26.0   101.0
activities without average heart rate: 6
              start             sport  minutes   km
2026-07-24 18:02:17          swimming     0.03  NaN
2025-09-27 19:43:38           running     0.04  NaN
2024-07-12 18:25:34           running     0.21 0.00
2026-07-02 20:33:24 fitness_equipment     0.96  NaN
2025-07-24 07:53:12           running     1.67 0.24
run max HR: highest 209, 99th percentile 202 bpm
runs by weekday: {'Fri': 108, 'Sat': 107, 'Mon': 103, 'Wed': 100, 'Tue': 41, 'Thu': 37, 'Sun': 1}

Four activities last under a minute: aborted starts, one of them a 0.2-minute run with no distance. Six have no average heart rate, so their load cannot be computed as recorded. The highest wrist reading on a run, 209 bpm, is probably the sensor locking onto cadence; the case file uses the 99th percentile, 202 bpm, as a stand-in for HRmax (not a tested maximum). The athlete ran on a Sunday once in two and a half years, so a Monday-to-Sunday week is a natural unit, and the last week of the export, which ends on a Saturday, is complete.

Step 3 · Visualize

Compute each activity's load, sum it by week starting on Monday, and keep every week between the first and the last, including weeks with nothing recorded.

PythonStep 3 · Weekly training load, raw

Show the expected result without running
127 weeks, 5 with nothing recorded; median 149 AU, largest 248 AU
Weekly training load from mid-2024 to late 2026. Most weeks lie between 100 and 200 AU; it drops to zero for two or three weeks in each December, with shorter dips at other times; the largest week, in July 2024, is near 250.

All five empty weeks fall over the December holidays; shorter dips come at other times. The watch recorded everything the athlete did, swims and hikes included, for two and a half years, so a week with nothing on it is most likely a week without training, and it stays in the series as zero. That is an assumption, and you should name it: if the watch had been left at home, those zeros would teach the model a rest that never happened. The largest week, in July 2024, holds an eight-hour hike. It is real load and stays.

Step 4 · Cleanse

Rules, written before the forecast is fitted, with a change log:

  1. Drop activities shorter than one minute (aborted starts).
  2. Fill a missing average heart rate with the median of the same sport, so a 37-minute run does not count as zero load.
  3. Drop the first week: the export starts on a Friday, so that week is partial.
PythonStep 4 · Rules, a change log and the clean weekly series

Show the expected result without running
                      rule  changed  left
        shorter than 1 min        4   689
average HR filled by sport        3   689
partial first week dropped        1   126
126 weeks, 5 at zero; median 149 AU, largest 248 AU

Step 5 · Features from the past only

Three features, each built only from weeks before the one being forecast:

The first four weeks lack a full history and cannot be used.

PythonStep 5 · Lag features and a trailing mean

Type a prediction to enable Run.

Show the expected result without running
126 weeks; 122 have all three features
                y   lag1   lag2  mean4
2024-07-29  133.0   68.0  248.0  130.0
2024-08-05  142.0  133.0   68.0  146.0
2024-08-12   55.0  142.0  133.0  148.0
correlation of each feature with the week's load: {'lag1': 0.64, 'lag2': 0.36, 'mean4': 0.46}

Last week goes with this week (correlation 0.64): this athlete's training comes in blocks, so a big week tends to follow a big week. That is exactly the pattern persistence uses, which makes it a hard baseline to beat.

Step 8 · Split by time and compare with persistence

The test set is the last 52 usable weeks, one full year from December 2025; the model learns only from the 70 weeks before them. A random split would let it learn from weeks after the one it predicts. Every method is scored by its mean absolute error (MAE) on the same test weeks.

A small gain in MAE can be luck. To check, take the gain week by week (persistence's miss minus the model's), then bootstrap it: draw 52 test weeks at random with replacement, average, and repeat 2000 times. If the middle 90% of those averages includes zero, the test year cannot tell the two methods apart.

PythonStep 8 · Five forecasts on the same 52 test weeks

Type a prediction to enable Run.

Show the expected result without running
train 70 weeks (2024-07-29 to 2025-11-24), test 52
persistence (last week)        MAE  38.4 AU
mean of last 4 weeks           MAE  45.0 AU
training-weeks mean            MAE  46.7 AU
linear on lags                 MAE  36.4 AU
centered 5-week mean (leaks)   MAE  28.0 AU
linear closer than persistence in 28 of 52 test weeks; mean gain 2.0 AU, 90% bootstrap interval -2.3 to 6.0
coefficients: {'lag1': 0.62, 'lag2': 0.09, 'mean4': -0.0} intercept 39.1

The regression beats persistence by 2.0 AU a week (36.4 against 38.4), and it was closer in 28 of the 52 weeks. That is not much. The bootstrap interval for the gain runs from -2.3 to +6.0 AU and includes zero, so the test year cannot tell the regression from "same as last week". Look at what it learned: most of its weight is on last week (0.62) plus a constant, so it is persistence pulled part of the way toward the usual week. The training mean and the 4-week mean, which ignore last week or dilute it, do clearly worse. The centered mean scores best of all and is useless: it uses the two weeks after the week it "predicts".

Step 3 again · The forecast against the weeks it predicted

PythonStep 3 again · Test weeks, persistence and the regression

Show the expected result without runningThe 52 test weeks of training load as black dots, the persistence forecast as a dashed step line one week behind, and the regression forecast as a solid gray line that follows persistence but stays closer to the middle. Both miss most at the December break and the dips in May and September.

Both forecasts are one week late at every turn: neither sees the December break or the dips in May and September coming, and both forecast a low week right after each one ends. In between, the regression follows persistence but sags below it in the big weeks of late 2026, because it pulls toward the usual week of the training period, which was lighter. A model that only knows past totals cannot know about a holiday or a planned taper; the coach can, and should overrule the number in those weeks.

Step 8 again · Next week, with a range

Persistence was not clearly beaten, so use it, and say so: it is simpler, and anyone can check it. The range comes from persistence's own test-week errors: the middle 80% of them, added to the forecast.

PythonStep 8 again · Next week's load and an 80% range

Type a prediction to enable Run.

Show the expected result without running
last four weeks: [217.0, 220.0, 173.0, 217.0] AU
week starting 2026-11-30: forecast 217 AU, 80% range 159 to 276 AU
the regression would say 191 AU

The range is wide, about 60 AU on each side, because one athlete's weeks are variable and 52 test weeks are a short history of errors. The regression gives a lower number, 191 AU, because it pulls a big week back toward the usual week; on the test year that habit was worth too little to trust. The number is a planning guide for the coach, not a target: it says what this athlete is likely to do next, not what he should do.

How good is the number?

The test set is a full year, 52 weeks. The regression's MAE (36.4 AU) is 2.0 AU better than persistence (38.4 AU), it was closer in 28 of 52 weeks, and a bootstrap of the week-by-week gain gives a 90% interval of −2.3 to +6.0 AU: no clear win. Both methods are one week late at every break and dip, which is where most of their error is. The training mean (46.7 AU) and the 4-week mean (45.0 AU) are clearly worse, because last week matters (correlation 0.64). The leak check is the centered 5-week mean: it "scores" 28.0 AU because it uses the weeks after the one it forecasts. The 80% range comes from 52 persistence errors and is itself rough.

Action card

Action card
Finding
Next week's load is best forecast as last week's; a regression on recent weeks did not do clearly better.
Evidence
On 52 test weeks, persistence missed by 38.4 AU on average and the regression by 36.4 AU; the gain's 90% bootstrap interval, −2.3 to +6.0 AU, includes zero.
How sure
Moderate: one athlete, one test year, and an 80% range of 159 to 276 AU around the forecast.
Action
Plan the week starting 30 November 2026 around 217 AU, about last week, expect anything from 159 to 276, and overrule the number yourself for holidays or a planned easy week.
Test again
Score persistence and the regression again after 13 more weeks, with the same bootstrap check.

Track it

The record gets a weekly row when you track load: date (the Monday that starts the week), test=watch-week, metric=training_load_au, value, unit=AU, device (the watch), protocol_version (the HRmax used, here 202 bpm), note (a week with nothing recorded is added as zero only if you know it was a week without training; note why).

Open your athlete record

With your own data

Export your own activity summaries from your watch's account (most makers offer a download of all activities, often as FIT files). Put each start on your local clock, compute moving minutes times (average heart rate / your HRmax) squared for each activity, and run this notebook from Step 3 on your weekly sums. Decide, and write down, whether an empty week was rest or a watch left at home.

Check the AI

Asked to "forecast next week's training load", an assistant wrote:

> I summed load by Monday-to-Sunday week, kept the empty December weeks as zero, built last > week, the week before and a centered 5-week rolling mean as features, and tested on the > last 52 weeks in time order. Mean error 28 AU, far better than "same as last week" at 38.

What is wrong with it?

The centered 5-week mean averages the two weeks after the week being forecast, so it puts the future into a feature. Everything else is right: Monday weeks, empty weeks kept, a split by time. With a trailing mean (shifted one week) the regression's error is back to 36.4 AU, within the noise of persistence's 38.4.

Check yourself

  1. Why are the empty December weeks kept in the series as zero?

  2. Why is mean4 built from week.shift(1) before the rolling mean?

  3. The regression's MAE is 2.0 AU lower than persistence's, but the 90% bootstrap interval of the gain runs from −2.3 to +6.0 AU. What should you conclude?

  4. The centered 5-week mean has the lowest error. Why is it not the forecast to use?

  5. Last week's load was 217 AU and the middle 80% of persistence's test errors ran from about −58 to +59 AU. What is the top of the 80% range for next week, in AU?

    AU (upper end)

0 of 5 answered · 0 right the first time

Challenge: A second load series

Repeat the forecast with a different weekly series: running kilometers per week from the same export, or your own watch export if you have a year or more.

  1. Write the cleaning rules (what is not a run, how a week is defined, what an empty week means) before you fit anything.
  2. Build lag1, lag2 and a trailing mean4 from the past only, and count the weeks lost at the start.
  3. Split by time with the last 52 usable weeks as the test set, and compare persistence, the training mean, the 4-week mean and a regression on lags.
  4. Count the test weeks in which your best method beats persistence, and bootstrap the gain.
  5. Give next week's forecast with an 80% range from the test errors, in one sentence for a coach.

Hand in

How it is judged

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

    Forecasting demand for a plant or a power grid starts the same way: the naive "same as last period" forecast is the benchmark every model must beat on a chronological split, and inputs must come from the past only. The Machine Learning for Engineers page on ARX time-series models builds the same kind of model from past outputs and inputs.

    Acknowledgements

    The activity summaries come from a COROS Training Hub archive, published in the course case file (athletes/jh/coros-history/).

    References

    Built 2026-12-02 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.