Learning objectives

01 Define a forecast and identify the frequency and horizon in a monthly example.

02 Distinguish local, global and foundation models by how they learn from data.

03 Use a global model and a pretrained model to forecast passenger demand.

What is a forecast?

It’s December 1959. You plan flights for an airline. How many passengers should you expect each month next year?

Observed monthly passengers through 1959 with 1960 left blank.

The line ends in December. You have to set the schedule before you know how many people will fly.

One possible path simulated for 1960.

A forecast uses what we know today to estimate future passenger numbers. Here’s one way 1960 could turn out.

What makes it a time series?

Each point shows the passenger count for one month. The time index tells us which month it belongs to.

The January 1955 point marks one observation on the time index. Target: monthly airline passengers. Frequency: one count per month. Annual averages rise over time. Summer peaks recur each year. The shaded region marks the twelve forecast months in 1960.

The airline needs a forecast for each of the 12 shaded months.

Local, global and foundation models

Local: fit a separate model to each route.
Global: fit one shared model across all three routes.
Foundation: apply a model pretrained on diverse datasets to the target history.

Transfer learning

Transfer learning means reusing what a model learned on one task for another. Here we fit NHITS on M4 Monthly and use those weights to forecast AirPassengers.

Source: M4 Monthly

The competition includes monthly series from finance, industry and other domains. We fit one model across many histories.

One anonymous M4 series, M1, shown against its month index.

Target: AirPassengers

We give the fitted model the airline’s monthly passenger counts through 1959 and ask it to forecast 1960.

Monthly international passenger counts through 1959, with 1960 held back.

Example: fitting a global model on M4 Monthly

NHITS is a neural network. Each training window uses 60 months to predict the next 12.

Python packages and training settings
from neuralforecast import NeuralForecast
from neuralforecast.models import NHITS

settings = dict(
    max_steps=2000, batch_size=32,
    stack_types=["identity"] * 3, n_blocks=[1, 1, 1],
    mlp_units=[[256, 256]] * 3, n_pool_kernel_size=[1, 1, 1],
    n_freq_downsample=[12, 4, 1], scaler_type="standard",
    random_seed=42, accelerator="cpu", logger=False,
    enable_progress_bar=False, enable_checkpointing=False,
)
horizon = 12
net = NHITS(
    h=horizon, input_size=5 * horizon, **settings
)
model = NeuralForecast(models=[net], freq="MS")
model.fit(df=m4_train)

Forecast AirPassengers with the fitted model

# Keep the series ID, month and observed count through December 1959
air_history = air.loc[air["ds"] < "1960-01-01", ["unique_id", "ds", "y"]]

# NHITS uses the 12-month horizon set during fitting
passenger_forecast = model.predict(df=air_history)
NHITS forecasts the next twelve months from the passenger history.

The orange line is the forecast made using observations through December 1959.

NHITS forecasts and the dashed teal line of observed 1960 passenger counts.

August 1960: about 517,000 forecast and 606,000 observed. The dashed line shows what happened.

Why use a foundation model?

  • Ease of use. Load a trained model and give it the history of the series you want to forecast.
  • Less training time and computing effort. The developers have already run pretraining. We only run prediction for this task.
  • A starting point for short histories. Patterns learned elsewhere may help a new route. Check its forecasts against a simple benchmark.

Examples include Chronos-2, TimeGPT and TimesFM. We’ll use Chronos-2 for the airline example.

Example: using Chronos-2 to make a forecast

from chronos import BaseChronosPipeline

chronos = BaseChronosPipeline.from_pretrained("amazon/chronos-2")
horizon = 12

def forecast(history):
    raw = chronos.predict_df(
        history, prediction_length=horizon, quantile_levels=[0.5],
        id_column="unique_id", timestamp_column="ds", target="y",
    )
    return raw[["ds", "0.5"]].rename(columns={"0.5": "forecast"})

Load the model once. The function asks it to forecast 12 future months from the history we pass in.

One pretrained model, two forecasts

m4_forecast = forecast(m4_history)
air_forecast = forecast(air_history)

M4 Monthly – series M1

Twelve forecast months beyond the cutoff for M4 Monthly – series M1The forecast with the later observed values overlaid as a dashed teal line.

AirPassengers – 1960

Twelve forecast months beyond the cutoff for AirPassengers – 1960The forecast with the later observed values overlaid as a dashed teal line.

History Median forecast Actual

Your turn

Which statement describes how we used Chronos-2 to forecast airline passengers? You have 10 seconds to choose A, B or C.

10 seconds

A. The model can forecast these counts without the passenger history.

B. It uses the passenger history and keeps its pretrained weights fixed.

C. It fits all its weights to the passenger history we supply.

Key takeaways

  • A forecast estimates what might happen over a chosen horizon using information available today.
  • A time series records a quantity in time order. Here we have one passenger count per month.
  • A local model learns from one series. A global model learns across series. We used a foundation model pretrained on many datasets and gave it a new history.

Appendix: how does Chronos-2 work?

Chronos-2 uses a transformer. It groups observations into short blocks and uses attention to give relevant information more weight.

Past observations become blocks. A transformer encoder uses time attention across blocks and, for grouped inputs, group attention across series. The forecast head produces future quantiles.

  • Time attention compares blocks from different times within a series.
  • Group attention shares information across related series supplied together.