Harsha Halgamuwe Hewage
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.
It’s December 1959. You plan flights for an airline. How many passengers should you expect each month next year?
The line ends in December. You have to set the schedule before you know how many people will fly.
A forecast uses what we know today to estimate future passenger numbers. Here’s one way 1960 could turn out.
Each point shows the passenger count for one month. The time index tells us which month it belongs to.
The airline needs a forecast for each of the 12 shaded months.
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.
The competition includes monthly series from finance, industry and other domains. We fit one model across many histories.
We give the fitted model the airline’s monthly passenger counts through 1959 and ask it to forecast 1960.
NHITS is a neural network. Each training window uses 60 months to predict the next 12.
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,
)# 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)The orange line is the forecast made using observations through December 1959.
August 1960: about 517,000 forecast and 606,000 observed. The dashed line shows what happened.
Examples include Chronos-2, TimeGPT and TimesFM. We’ll use Chronos-2 for the airline example.
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.
History Median forecast Actual
Which statement describes how we used Chronos-2 to forecast airline passengers? You have 10 seconds to choose A, B or C.
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.
Chronos-2 uses a transformer. It groups observations into short blocks and uses attention to give relevant information more weight.