Sub topic 4
Baselines you must beat: naive and seasonal naive
A gradient boosting model with dozens of features can look impressive and still lose to a one-line rule. This chapter covers the two rules every forecast should be compared against, how to compute them at any horizon, and how to score them on the same rows as your model. It assumes you know the error metrics from the previous chapter (MAE, RMSE, MASE) and are comfortable with pandas shift and DatetimeIndex.
Why a baseline comes first
An error figure means nothing alone. An MAE of 12 units is excellent for a series that swings by 500 and poor for one that swings by 15. A baseline gives the number a reference point. It also gives you a stopping rule. If a tuned model cannot beat a rule that needs no training, the problem is in the features, the validation, or the data, and more tuning will not fix it.
Baselines also expose mistakes. If your model beats seasonal naive by 90 percent, suspect leakage before you celebrate.
The two baselines
Both predict the future by copying the past.
| Baseline | Forecast for time t | Best when |
|---|---|---|
| Naive | The last observed value, `y[t-1]` | The series is a slow random walk with no repeating pattern |
| Seasonal naive | The value one season earlier, `y[t-m]` | The series repeats with period `m` |
The period m is the number of steps in one cycle:
- Daily data with a weekly pattern:
m = 7. - Monthly data with a yearly pattern:
m = 12. - Hourly data with a daily pattern:
m = 24. - Hourly data with a weekly pattern:
m = 168.
Naive is the same as seasonal naive with m = 1. In your feature table these baselines already exist as columns: lag_1 is the naive forecast and lag_7 is the seasonal naive forecast for daily data. That is why the earlier model-fitting example could score both on test['lag_1'] and test['lag_7'] with no extra code.
Forecasting at a horizon h
For one-step forecasts the rule is simple. For a horizon of h steps, the forecast origin is h steps before the target, so you can only use values from the origin or earlier. The naive baseline becomes y[t-h], which is the last value you had at the origin.
The seasonal version needs the most recent same-phase value that was already known at the origin. That is y[t - m*k], where k = ceil(h / m) is the smallest number of whole seasons that reaches back past the origin. With m = 7, a horizon of 1 to 7 uses a lag of 7, and a horizon of 8 to 14 uses a lag of 14.
The following script builds a synthetic daily series with a weekly pattern, computes both baselines at three horizons, and scores them on the final 20 percent of the data, including MASE.
import numpy as np
import pandas as pd
from sklearn.metrics import mean_absolute_error
rng = np.random.default_rng(0)
idx = pd.date_range('2024-01-01', periods=365, freq='D')
weekly = np.array([20, 22, 25, 24, 30, 45, 40])
y = pd.Series(
100 + weekly[idx.dayofweek.to_numpy()] + rng.normal(0, 3, len(idx)),
index=idx,
)
def naive(s, h=1):
# Forecast for time t is the last value known at the origin t-h.
return s.shift(h)
def seasonal_naive(s, m=7, h=1):
# Smallest whole number of seasons that reaches back past the origin.
k = m * int(np.ceil(h / m))
return s.shift(k)
cut = int(len(y) * 0.8)
train, test = y.iloc[:cut], y.iloc[cut:]
# MASE scale: in-sample MAE of the seasonal naive forecast on the training data.
m = 7
scale = np.mean(np.abs(train.values[m:] - train.values[:-m]))
rows = []
for h in (1, 7, 14):
for name, fc in (('naive', naive(y, h)), ('seasonal_naive', seasonal_naive(y, m, h))):
pred = fc.loc[test.index]
mae = mean_absolute_error(test, pred)
rows.append({'horizon': h, 'method': name, 'MAE': mae, 'MASE': mae / scale})
print(pd.DataFrame(rows).round(2).to_string(index=False))Because noise has standard deviation 3, you should see these patterns. The seasonal naive MAE sits near 3.4 at every horizon up to 14. The naive MAE is much larger, around 8, because it ignores the weekly cycle. The exact values depend on the seed, but the gap between the two methods should not.
Two details in the code matter. First, shift runs on the full series y, not on test alone, so the first test rows use values from the end of the training period. That is legitimate, because those values were known at the forecast origin. Second, the MASE scale comes from the training portion only. Computing it on test data would let test information shape your metric.
Scoring baselines fairly
Follow these rules whenever you compare a model with a baseline:
- Evaluate both on the same rows. A feature table built with
dropna()loses its first rows, because the longest lag and rolling window are undefined there. Score the baseline on the rows the model scores, not on a longer span. - Use the same horizon. A model trained for one-step prediction should be compared with the one-step baseline, not with a baseline that is 14 steps stale.
- Report a ratio.
MAE_model / MAE_baseline, or MASE directly, below 1 means the model wins. A ratio of 0.95 is a small gain, and you should check whether it holds across folds. - Compare on walk-forward folds, not a single split. One test window can favor either method by chance.
Choosing between them
Edge cases
- Irregular or gapped timestamps.
shift(7)moves seven rows, not seven days. If days are missing, the baseline silently uses the wrong day. Calls.asfreq('D')first so gaps become explicitNaNrows, then decide how to fill them. - Missing values in the lagged position. A
NaNatt-mgives aNaNforecast. Drop those rows from the model and the baseline together, or the comparison is unfair. - Intermittent demand. When many values are zero, naive forecasts zero after any zero, and MAPE is undefined or huge. Use MAE or MASE.
- Two seasonal cycles. Hourly data often has daily and weekly cycles. Compare
m = 24andm = 168and keep the stronger baseline. The better one is the bar to beat. - Moving holidays. Seasonal naive copies the previous week even when that week had a holiday and the target week does not. Errors around holidays are expected and are a hint that calendar features will help.
- Noisy series. Seasonal naive copies one noisy observation, noise included. A stronger variant averages the same phase over the last few seasons. Add it as a third baseline if the data is noisy, but keep plain seasonal naive for MASE scaling because it is the standard.
- Trending series. Naive and seasonal naive both lag a trend by one step or one season. If the series climbs steadily, a drift baseline (last value plus the average historical change per step) is worth adding.
What the baseline tells you next
The baseline results guide the rest of the work:
- Seasonal naive far ahead of naive: the series has strong seasonality, and
lag_mwill be among your most important features. - Seasonal naive and naive about equal: weekly or yearly structure is weak, and recent lags and rolling means matter more.
- Your model barely beats seasonal naive: the lag features already encode the signal. Gains will come from calendar effects, external regressors, or better validation, not a larger model.
Exercise
A daily series has a weekly cycle. You forecast 10 days ahead using seasonal naive with m = 7. Which lag should you use for the target at time t, and why is shift(7) wrong here?
Show answer
Use a lag of 14, because k = ceil(10 / 7) = 2 seasons gives 7 * 2 = 14. The forecast origin is 10 days before the target, and y[t-7] lies after that origin (3 days after it), so it would not yet be known when the forecast is made. Using shift(7) for a 10-day horizon is look-ahead bias and makes the baseline look better than it can really be.
Exercise
On a test set, naive has MAE 8.4 and seasonal naive has MAE 3.4. Your model has MAE 3.3. Is the model worth keeping, and what would you check next?
Show answer
Not yet. The model improves on seasonal naive by only about 3 percent (3.3 / 3.4 is roughly 0.97), which could be chance on a single split. Score both on several walk-forward folds on identical rows, and check whether the model wins on most folds. If the gain stays small, look for gains in calendar features or external regressors rather than model tuning.