Sub topic 4
Baselines you must beat: naive and seasonal naive
This chapter assumes you can use pandas shift and a DatetimeIndex, and that you know MAE from the previous chapter. A baseline is a forecast so simple that it needs no training. Any model you build has to beat it. If it doesn't, the extra complexity gives you nothing.
The two baselines
The naive forecast predicts that the next value equals the last observed value. For a daily series, the forecast for today is yesterday's value. It is the same as the lag_1 feature.
The seasonal naive forecast predicts that the next value equals the value one full season ago. With daily data and a weekly cycle, the forecast for today is the value from seven days ago. It is the same as lag_7.
| Baseline | Forecast for time t | Works well when |
|---|---|---|
| Naive | y(t-1) | The series changes slowly and has no strong cycle |
| Seasonal naive | y(t-m) | A repeating pattern of length m dominates |
Here m is the season length in rows: 7 for daily data with a weekly pattern, 12 for monthly data with a yearly pattern.
Computing them
Both baselines are one shift call. Score them on the same chronological test rows your model will use.
import numpy as np
import pandas as pd
from sklearn.metrics import mean_absolute_error
idx = pd.date_range("2024-01-01", periods=200, freq="D")
rng = np.random.default_rng(0)
weekly = 10 * np.sin(2 * np.pi * np.asarray(idx.dayofweek) / 7)
y = pd.Series(100 + weekly + rng.normal(0, 2, len(idx)), index=idx)
cut = int(len(y) * 0.8)
train, test = y.iloc[:cut], y.iloc[cut:]
naive = y.shift(1).iloc[cut:]
seasonal = y.shift(7).iloc[cut:]
mae_naive = mean_absolute_error(test, naive)
mae_seasonal = mean_absolute_error(test, seasonal)
# MASE: divide by the in-sample MAE of the one-step naive forecast
scale = train.diff().abs().mean()
print("naive MAE ", round(mae_naive, 2))
print("seasonal naive MAE", round(mae_seasonal, 2))
print("naive MASE ", round(mae_naive / scale, 2))
print("seasonal MASE ", round(mae_seasonal / scale, 2))On this series the seasonal naive error is much lower, because the weekly cycle is strong. The naive forecast is wrong by roughly the full day-to-day swing in the cycle.
Reading the result
MASE (mean absolute scaled error) divides your MAE by the training-set MAE of the naive forecast. A MASE below 1 means you beat the naive forecast. A MASE above 1 means you lose to it. Because it is a ratio, you can compare it across series with different units.
Use the stronger baseline as your target. If the series is seasonal, that is usually seasonal naive. A gradient boosting model that beats naive but loses to seasonal naive has not learned the seasonality.
Common errors
- Wrong season length. Using
shift(7)on monthly data gives a meaningless baseline. Set m from the data's frequency and cycle. - Baseline on the training rows. Report baseline errors on the test period only, the same period you use for the model.
- Multi-step mismatch. For a horizon of h steps, the naive forecast is y(t-h), not y(t-1). Shift by the horizon, or the baseline will look better than it can be in practice.
Exercise
Your daily sales series has a strong weekly cycle. Your model has MAE 4.1. Naive MAE is 9.0 and seasonal naive MAE is 3.8. Has the model succeeded, and what would you check next?
Show answer
No. The model beats naive but loses to seasonal naive, which is the stronger baseline for this series. Check that the model has lag_7 (or day-of-week) features and that it is scored on the same test rows as the baselines. Then see whether tuning or extra features bring its MAE below 3.8.