Teaching sample · Worked exercise

Forecasting a demand series: from naive baseline to a stock decision

A 90-minute exercise for MSc business analytics or final-year computing students. It teaches four habits I consider non-negotiable in applied forecasting: start with a baseline, split data in time order, report error with its context, and finish with the decision the forecast is for.

Synthetic data The series below is generated by a seeded function in this page's source code. It is not from any client, employer or competition.

1. The setting

A retailer stocks a single product and orders from its supplier once a week. Deliveries arrive two weeks after an order is placed. We have three years of weekly sales (156 weeks). The buyer wants to know how much to order this week so that the product is available about 95% of the time without holding more stock than necessary.

Before touching a model, ask the class: who uses the forecast, what do they decide, and what does it cost to be wrong in each direction?

2. Split the data in time order

We hold back the last 26 weeks as a test set and fit on the first 130. Students often reach for a random split; the exercise asks them to explain why that would let the model "see the future" and produce optimistic error estimates.

Synthetic data Weekly demand with a chronological train/test split and the seasonal-naive forecast A line chart of 156 weeks of synthetic demand. The first 130 weeks (training) are drawn in dark ink, the final 26 weeks (test) in teal, and the seasonal-naive forecast for the test weeks as a dashed amber line. A vertical dotted line marks the split. 0 20 40 60 80 Train (130 wks) Test (26) Week 1 Week 156 Units
Dark line: training weeks. Teal: test weeks (actual demand). Dashed amber: seasonal-naive forecast, i.e. the value from the same week one year earlier. All values synthetic.

3. Baselines first

Three forecasts that need no fitting at all. Each is computed on the training data and evaluated on the 26 test weeks.

Method MAE (units) Bias (units) MASE
Naive (last value) 14.3 -14.3 2.08
Moving average (8 weeks) 7.2 -2.3 1.04
Seasonal naive (same week last year)lowest MAE 5.9 -3.3 0.85

Discussion points. MAE is in the units the buyer orders in, which is why we lead with it. Bias tells us whether a method systematically over- or under-forecasts; a method with low MAE but persistent positive bias will quietly build excess stock. MASE scales the error by the in-sample seasonal-naive error, so a value below 1 means "better than repeating last year" and results can be compared across products with different volumes.

On this series the seasonal naive (same week last year) method wins because the data has strong annual seasonality and only a gentle trend. That is the lesson, not the specific number: a method that costs nothing sets the bar that every fitted model must clear. In the follow-up session students fit an exponential-smoothing model and a gradient-boosted model and discover how little they gain on a series like this, and how much more they gain on a promotional one.

4. From forecast to order quantity

The buyer reviews stock weekly (R = 1) and deliveries take two weeks (L = 2), so an order placed today must cover demand over the next L + R = 3 weeks. We use an order-up-to policy:

order-up-to level  S = forecast demand over (L + R)  +  z × σ × √(L + R)
order quantity     Q = S − inventory position
inventory position = on hand + on order
Forecast for the next 3 weeks51 + 60 + 62 = 173 units
Weekly error σ (≈ 1.25 × MAE of the chosen method)7.4 units
Service-level factor z for ~95%1.645
Safety stock = z × σ × √321.0 units
Order-up-to level S194.0 units
Inventory position (on hand 95 + on order 40)135 units
Order quantity Q59 units

Students are asked to state the assumptions they have just made: errors are roughly normal and independent week to week; the seasonal pattern will repeat; the supplier delivers on time; and a 95% service level is what the business actually wants. Each of those is a conversation with the buyer, not a modelling choice.

5. What students hand in

  • The error table, reproduced from their own code.
  • The order quantity with its working.
  • About 200 words answering: which method would you recommend to the buyer, what could go wrong, and what would you want to know before trusting the forecast for a product that sells only a few units a month?

Notes for instructors

  • The synthetic generator (level + trend + annual sine + normal noise, seeded) is deliberately simple so that students can reason about why seasonal naive wins. Swap in a real public series, such as a retail dataset from a forecasting competition, for the follow-up session.
  • The 1.25 × MAE rule of thumb for converting MAE to standard deviation assumes normal errors; ask stronger students to compute the residual standard deviation directly and compare.
  • Common misconceptions to surface: that a lower MAE always means a better decision; that seasonality can be ignored if the trend is modelled; that a random split is acceptable if the model does not "use time".