Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 40 ยท Getting Started

The Forecasting Workflow and Baselines

Learn the time series forecasting workflow, split data by time, and build naive, seasonal naive, mean and drift baselines that every fancy model must beat.

Before you fit anything clever, you need a yardstick. Forecasting has a very simple rule: a complicated model is only worth its complexity if it beats a trivial one. The trivial ones, called baselines or benchmarks, take a few lines of code, and they are often surprisingly hard to beat. This lesson sets out the overall workflow and builds the four standard baselines.

The workflow

flowchart LR
    A["Define the question: horizon and loss"] --> B["Collect and clean data"]
    B --> C["Plot and explore"]
    C --> D["Split by time"]
    D --> E["Fit baselines"]
    E --> F["Fit better models"]
    F --> G["Compare on held-out data"]
    G --> H["Refit on everything and forecast"]

Every step uses only the past relative to what it predicts.

Two decisions come first. The horizon is how far ahead you must predict (next day? next 12 months?), and it changes which models are suitable. The loss is how you measure a miss: is an over-forecast as costly as an under-forecast? The evaluation chapter covers this in depth.

Split by time, never at random

Keep the earliest part of the series for training and the latest part for testing. The test set should be as long as the horizon you care about.

Python A chronological train/test split

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

No row of the test set may influence anything the model learns: not its parameters, not a scaling statistic, not a missing-value fill.

Four baselines

Each baseline is a different guess about what stays constant.

Baseline Forecast for every future step Works well when
Mean the average of the training data the series just wobbles around a level
Naive the last observed value the series is a random walk (stock prices)
Seasonal naive the value from the same season last cycle strong seasonality
Drift last value plus the average historical change per step a steady trend
Python Compute all four baselines

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The seasonal naive forecast is simply a copy of the last full cycle. The drift line extends the straight line between the first and last training points.

Score them

The simplest error measures are the mean absolute error (MAE) and the root mean squared error (RMSE). MAE is in the units of the data and treats all misses equally; RMSE punishes large misses more.

Python Which baseline wins?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Here the drift line wins, because the trend (about 36 units a year) is larger than the seasonal swing. Naive and seasonal naive land close together: naive ignores the season, and seasonal naive ignores the growth because it repeats last year's level. No baseline captures both; a good model must. That is where the next chapters take you: first separate trend and season (decomposition), then model each.

A pitfall: judging by the training fit

Models fit to the training data always look good there. What counts is the error on data they have not seen.

Python In-sample versus out-of-sample

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Both numbers use the same seasonal naive rule here, so they are close; for models with many parameters the gap grows, and that gap is overfitting.

Report every new model as "x% better than seasonal naive". A relative claim against a simple baseline is far more convincing than a bare error number.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the naive forecast predict for every future step?

    Naive repeats the most recent observation; it is the optimal forecast for a random walk.
  2. 2. Which baseline suits strongly seasonal data best?

    Seasonal naive repeats the value from the same position in the previous cycle, capturing the seasonal pattern.
  3. 3. Why should the test set be the most recent part of the data?

    A real forecast is made from the past into the future, so the test must lie after the training data.
  4. 4. Compared with MAE, RMSE...

    Squaring before averaging gives large errors a disproportionate weight.

Summary

  • Follow a workflow: define the question, clean, explore, split by time, baseline, model, compare, refit.
  • Hold out the most recent block of data for testing, as long as your forecast horizon.
  • Mean, naive, seasonal naive and drift are the standard benchmarks.
  • MAE is robust and readable; RMSE punishes large misses.
  • Always judge on unseen data and relative to a baseline.

Next: Trend, Seasonality and Noise