lesson
50 min

Forecasts and Baselines

Build simple forecasts, measure their error, and learn why every model must beat a baseline.

Objective

By the end of this lesson, you can build two baseline forecasts, measure them with mean absolute error, and explain why a model must beat a baseline.

Start with a baseline

A baseline is the simplest reasonable forecast. If your fancy model cannot beat it, the model is not worth using.

Two common baselines:

  • Naive: tomorrow will be the same as today.
  • Seasonal naive: this Monday will be the same as last Monday.

Measuring error

Mean absolute error (MAE) is the average size of your misses, ignoring whether you guessed high or low. Smaller is better. It is in the same units as your data, which makes it easy to explain.

Run it. Two weeks of made-up daily demand have a weekly pattern (weekends are low). Compare the naive and seasonal naive forecasts for week 2. Which wins?
Python 3
Ctrl+Enter to run | Tab to indent | Python runs in your browser via Pyodide

The seasonal baseline wins easily because it knows weekends are different. Any real model for this data must beat an MAE of 3.0 to be worth it.

Beyond baselines

Real forecasting tools, like the statsmodels library, model trend and season together. Run this in Colab once your data is a daily series:

import pandas as pd
from statsmodels.tsa.holtwinters import ExponentialSmoothing

series = pd.read_csv("daily_demand.csv", parse_dates=["date"], index_col="date")["demand"]
train, test = series[:-14], series[-14:]   # hold out the last two weeks

model = ExponentialSmoothing(train, trend="add", seasonal="add", seasonal_periods=7).fit()
forecast = model.forecast(14)
print("Model MAE:", (forecast - test).abs().mean())

Notice the split: train on the past, test on the most recent days. Never shuffle time series data before splitting, or the model gets to peek at the future.

A national example

Judgment check

Forecasts fail on unusual days: storms, holidays, emergencies. If a forecast drives decisions that affect people's safety, like staffing a cooling center, plan for what happens when it is wrong. A forecast should come with a range, not just one number.

Quiz: Forecast check

  1. 01Your model's MAE is 4.0. The seasonal naive baseline's MAE is 3.0. What should you do?

    Choose one.

  2. 02How should you split time series data into train and test sets?

    Choose one.

Ask. Answer. Build together.