FDE Times dataFDE jobs open 932▼14 Change in open roles over 7 days, like-for-like: roles from companies we started tracking this week are left outNew in 7 days 62Companies hiring 202Remote-friendly 24%Median US pay $201kTop hirer Databricks 92
中文VI

The newspaper of the Forward Deployed Engineer

Guides

When copying last week beats the client's forecasting model

An error measured on training data should not set a shift roster; naive baselines and a backtest on unseen weeks show whether the model has earned the job.

ShareLinkedInFacebookX

In brief

  • Every forecasting model should be compared with naive and seasonal naive over the same horizon.
  • Error on training data says nothing about how well a model will forecast; a rolling-origin backtest answers that question.
  • Translate error into operating decisions, because clients schedule shifts and trucks and have no use for MAE on its own.
Dot chart comparing the MAE of a seasonal naïve forecast and the client's model by week, with the axis starting at 0. Week 101: 3.9 and 4.4. Week 102: 4.6 and 4.9. Week 103: 4.2 and 4.1, the only week the model wins. Week 104: 5.3 and 6.6. Average: 4.5 and 5.0. A dashed line marks the 2.4 figure shown on the slide.
The model once boasted an error of 2.4 orders; it now misses by 5.0 on average across four 7-day windows, losing to seasonal naïve at 4.5. Source: assumed figures in the article.

An error of just 2.4 orders a day is the figure on the operations director’s slide. Take this hypothetical first week at a logistics company: she is presenting a model that forecasts warehouse orders, and she wants to use it to schedule shifts from next month.

You ask what data the figure was measured on. The answer is the data the model was trained on. It shows how well the model remembers the past and says nothing yet about next week.

Next month the whole warehouse will turn up to work according to that number, so you need to pin it down before the shifts are set. A mistake here means too many people or too few trucks rather than a metric that looks off on a dashboard. Don’t assume the client’s team has already checked.

Copying the past is a model too

There are two baselines to build in your first session. With naive, every forecast equals the last observed value. With seasonal naive, each forecast equals the most recent value from the same season: the same weekday last week, if the cycle is one week.

Neither is meant to be the final answer. The textbook Forecasting: Principles and Practice (FPP3) uses simple methods as benchmarks to ensure that a new method is genuinely better, and that is where their value lies. Without a baseline, “the model is off by 2.4 orders” tells you nothing.

Work through some made-up figures. In week 100 the warehouse receives 100, 95, 98, 102, 130, 180 and 170 orders from Monday to Sunday. In week 101 the actual numbers are 104, 99, 96, 106, 128, 186 and 165, and the whole week has to be forecast the moment week 100 closes.

Naive takes Sunday’s number, so it forecasts 170 orders for all seven days. Its absolute errors total 338, an MAE of about 48.3 orders a day. Seasonal naive copies week 100 as it stands. Its errors total only 27, an MAE of about 3.9.

Turn error into people and trucks

Clients don’t schedule shifts by MAE, so convert it into their units. Suppose one worker picks 20 orders per shift. With naive, Monday’s forecast is 66 orders too high, which means calling in more than three people too many. With seasonal naive, the average error of 3.9 orders is less than one person’s work.

The same arithmetic works for trucks. If each truck carries 30 orders, naive’s 66 surplus orders are more than two trucks booked for nothing, while seasonal naive’s worst day is off by only 6 orders, a fifth of a truck.

To make that conversion, ask the operations team three things at the outset: which decision does this forecast serve, how far ahead is it made, and at what level? If shifts are fixed 7 days ahead, the horizon is 7 days, and every measurement must use that horizon.

FPP3 also notes that one-step error may not be relevant when multi-step forecasts are needed, and that the evaluation procedure can be modified to measure error at step h. A one-day-ahead error is no help to someone who set the shifts a week ago.

Backtesting has one hard rule

Rob Hyndman describes this kind of evaluation as a forecast origin that rolls forward in time. The rule is brief: the training set contains only observations that occurred before the observation used for testing. The errors are then averaged over the test sets.

Apply it to 104 weeks of history and four 7-day windows. The calculation above is the first window: train through the end of week 100 and score on week 101. The last window trains through week 103 and is scored on week 104. The training set grows each time, as it does in scikit-learn’s TimeSeriesSplit.

The code takes only about 20 lines. Write it by hand once to see where the data is cut, and make the forecast function a parameter so that every method is scored on the same windows:

import numpy as np
import pandas as pd

def naive(train, h):
    return [train.iloc[-1]] * h

def seasonal_naive(train, h, season=7):
    # assumes h <= season
    return train.iloc[-season:].values[:h]

def backtest(y, forecast_fn, h=7, n_windows=4):
    # y: daily pd.Series, sorted by time, with no missing days
    rows = []
    for w in range(n_windows, 0, -1):
        cutoff = len(y) - w * h
        train = y.iloc[:cutoff]              # only data before the origin
        test = y.iloc[cutoff:cutoff + h]
        forecast = np.asarray(forecast_fn(train, h))
        mae = abs(test.values - forecast).mean()
        rows.append({"start_date": y.index[cutoff], "mae": mae})
    return pd.DataFrame(rows)

Each call to backtest returns its own DataFrame, so merge them on the start date to get two columns to compare:

comparison = backtest(y, naive).merge(
    backtest(y, seasonal_naive),
    on="start_date",
    suffixes=("_naive", "_seasonal"),
)

To test the client’s model, wrap it in a function that takes train and h, retrains on train in each window and returns h forecast values. Then merge its results in the same way.

When the client has many series, stop extending this loop by hand. The documentation for Nixtla’s StatsForecast describes cross-validation as a sliding window across the history that forecasts the period following it. The step_size parameter is the distance between windows, or how often the forecast is run. Match it to how often the client sets shifts.

Amazon Forecast measures this way as well: its documentation uses backtests to evaluate a predictor’s accuracy. The table below is cut to four windows so it is easy to follow; 104 weeks of history leave you enough data to run more before drawing a conclusion.

7-day window Seasonal naive MAE Client’s model MAE
1 (week 101) 3.9 4.4
2 (week 102) 4.6 4.9
3 (week 103) 4.2 4.1
4 (week 104) 5.3 6.6
Average 4.5 5.0

These numbers are also illustrative, but read them as you would in front of the client. The model that boasted 2.4 orders is off by 5.0 on average once it has to forecast for real. It loses to the baseline’s 4.5 and wins only one window out of four. Open window 4 first, because that is where the gap is widest.

Those four weeks may have been unusually calm, so hold off on a verdict. Run more windows covering the peak weeks in the 104-week history, then make your recommendation.

If the result holds, what you tell the operations director can be brief: “The model doesn’t yet beat copying last week. Next week we can schedule shifts with the baseline, and the model goes in when it beats the baseline on this same measure.” You aren’t sinking anyone’s project. You are giving the client an option that works now and a target that can be measured.

If it goes the other way and the model wins most windows, convert the difference into people and trucks before discussing deployment. The client then knows what they gain over the cheapest alternative.

A MASE below 1 is no victory yet

In this example, MASE divides the model’s error by the average error of one-step naive on the training data. According to FPP3, a result below 1 means better than the average one-step naive forecast, and above 1 means worse.

Hyndman and Koehler proposed MASE as the standard measure for comparing accuracy across multiple series. It is convenient, but a number below 1 invites early celebration.

Go back to window 1, which trains through the end of week 100 and is scored on week 101. To keep the arithmetic easy, assume the average day-to-day change across all the training data equals that of week 100: six differences adding up to 100, or about 16.7 on average.

The model is off by 4.4 orders, for a MASE of about 0.26, which sounds impressive. Seasonal naive is off by 3.9 orders and scores about 0.23, still better than the model.

The 0.26 does not prove the model is good. This series has a clear weekly cycle, and the weekend jumps inflate the one-step denominator, so scoring below 1 is fairly easy.

Always report MASE next to the seasonal naive figure, never on its own. When you read a score from your own tool, check which denominator it uses before comparing it with the numbers here.

Mistakes that make a backtest pretty and useless

The first mistake is using random K-fold out of habit. The scikit-learn documentation explains why it is wrong for time-ordered data: the model would be trained on the future and scored on the past.

Even with the data cut correctly, features can leak. A rolling average or a normalization computed over the whole series has already carried the future into the past. So has a promotion calendar finalized late, if it would not exist when the real forecast is made. Ask of every feature: on the day shifts are set, does this number exist yet?

Another trap is choosing windows that are too calm. A few ordinary weeks say nothing about how the model will behave in a peak week, so the backtest should cover peak season and periods when operations changed.

Reading the results has its own traps. A single window may be one lucky week, and an average can hide the worst window, so look at the whole table window by window before concluding.

The remaining trap sits in the client’s own data. Zero sales on a day when stock ran out does not mean zero demand, and you will teach the model something false if you leave those days unflagged. Check against the inventory history before trusting the sales series.

Get the order right, then put real numbers on your resume

In the first week, agree the horizon with the operations team, then get a baseline running before anyone starts discussing model architecture.

On your resume, don’t just list algorithms. Describe the work, for example “multi-window backtest at a 7-day horizon, reduced MAE versus seasonal naive,” with your own real figures.

When a job description mentions forecasting or supply chain, ask which baseline they compare their model with. In the interview, bring up the baseline before you are asked.

The next time someone shows off a handsome error figure, skip the question about which model they used. Ask how it compares with last week.

Was this article useful?

Use with your AI assistantAsk Claude ↗Ask ChatGPT ↗
8 sources
Read next on the roadmap · Stage 2: Broad engineeringYour voice agent yields on a laptop. Production may differA trial insurance hotline on LiveKit shows how to protect a legal notice, let callers cut in and hand off through the client's SIP trunk.