AutoGluon Time Series - Forecasting Quick Start

Open In Colab Open In SageMaker Studio Lab

Via a simple fit() call, AutoGluon can train and tune

  • simple statistical models (e.g., ETS, Theta),

  • tree-based models (e.g., LightGBM),

  • deep learning-based foundation models (e.g., Chronos, Toto),

  • an ensemble that combines predictions of other models

to produce multi-step ahead probabilistic forecasts for univariate time series data.

This tutorial demonstrates how to quickly start using AutoGluon to generate hourly forecasts for the M4 forecasting competition dataset.

Loading time series data as a TimeSeriesDataFrame

First, we import some required modules

import pandas as pd
from autogluon.timeseries import TimeSeriesDataFrame, TimeSeriesPredictor

To use autogluon.timeseries, we will only need the following two classes:

  • TimeSeriesDataFrame stores a dataset consisting of multiple time series.

  • TimeSeriesPredictor takes care of fitting, tuning and selecting the best forecasting models, as well as generating new forecasts.

We load a subset of the M4 hourly dataset as a pandas.DataFrame

df = pd.read_csv("https://autogluon.s3.amazonaws.com/datasets/timeseries/m4_hourly_subset/train.csv")
df.head()
item_id timestamp target
0 H1 1750-01-01 00:00:00 605.0
1 H1 1750-01-01 01:00:00 586.0
2 H1 1750-01-01 02:00:00 586.0
3 H1 1750-01-01 03:00:00 559.0
4 H1 1750-01-01 04:00:00 511.0

AutoGluon expects time series data in long format. Each row of the dataframe contains a single observation (timestep) of a single time series represented by

  • unique ID of the time series ("item_id") as int or str

  • timestamp of the observation ("timestamp") as a pandas.Timestamp or compatible format

  • numeric value of the time series ("target")

The raw dataset should always follow this format with at least three columns for unique ID, timestamp, and target value, but the names of these columns can be arbitrary. It is important, however, that we provide the names of the columns when constructing a TimeSeriesDataFrame that is used by AutoGluon. AutoGluon will raise an exception if the data doesn’t match the expected format.

train_data = TimeSeriesDataFrame.from_data_frame(
    df,
    id_column="item_id",
    timestamp_column="timestamp"
)
train_data.head()
target
item_id timestamp
H1 1750-01-01 00:00:00 605.0
1750-01-01 01:00:00 586.0
1750-01-01 02:00:00 586.0
1750-01-01 03:00:00 559.0
1750-01-01 04:00:00 511.0

We refer to each individual time series stored in a TimeSeriesDataFrame as an item. For example, items might correspond to different products in demand forecasting, or to different stocks in financial datasets. This setting is also referred to as a panel of time series. Note that this is not the same as multivariate forecasting — AutoGluon generates forecasts for each time series individually, without modeling interactions between different items (time series).

TimeSeriesDataFrame inherits from pandas.DataFrame, so all attributes and methods of pandas.DataFrame are available in a TimeSeriesDataFrame. It also provides other utility functions, such as loaders for different data formats (see TimeSeriesDataFrame for details).

Training time series models with TimeSeriesPredictor.fit

To forecast future values of the time series, we need to create a TimeSeriesPredictor object.

Models in autogluon.timeseries forecast time series multiple steps into the future. We choose the number of these steps — the prediction length (also known as the forecast horizon) — depending on our task. For example, our dataset contains time series measured at hourly frequency, so we set prediction_length = 48 to train models that forecast up to 48 hours into the future.

We instruct AutoGluon to save trained models in the folder ./autogluon-m4-hourly. We also specify that AutoGluon should rank models according to mean absolute scaled error (MASE), and that data that we want to forecast is stored in the column "target" of the TimeSeriesDataFrame.

predictor = TimeSeriesPredictor(
    prediction_length=48,
    path="autogluon-m4-hourly",
    target="target",
    eval_metric="MASE",
)

predictor.fit(
    train_data,
    presets="medium_quality",
    time_limit=600,
)
Beginning AutoGluon training... Time limit = 600s
AutoGluon will save models to '/home/ci/autogluon/docs/tutorials/timeseries/autogluon-m4-hourly'
=================== System Info ===================
AutoGluon Version:  1.6.2.dev0
Python Version:     3.13.11
Operating System:   Linux
Platform Machine:   x86_64
Platform Version:   #1 SMP Thu Jun 25 14:43:50 UTC 2026
CPU Count:          8
Pytorch Version:    2.13.0+cu130
CUDA Version:       13.0
GPU Memory:         GPU 0: 14.57/14.57 GB
Total GPU Memory:   Free: 14.57 GB, Allocated: 0.00 GB, Total: 14.57 GB
GPU Count:          1
Memory Avail:       28.76 GB / 30.94 GB (92.9%)
Disk Space Avail:   213.75 GB / 255.99 GB (83.5%)
===================================================
Setting presets to: medium_quality

Fitting with arguments:
{'enable_ensemble': True,
 'eval_metric': MASE,
 'hyperparameters': 'light',
 'known_covariates_names': [],
 'num_val_windows': 1,
 'prediction_length': 48,
 'quantile_levels': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9],
 'random_seed': 123,
 'refit_every_n_windows': 1,
 'refit_full': False,
 'skip_model_selection': False,
 'target': 'target',
 'time_limit': 600,
 'verbosity': 2}
Inferred time series frequency: 'h'
Provided train_data has 148060 rows, 200 time series. Median time series length is 700 (min=700, max=960).

Provided data contains following columns:
	target: 'target'

AutoGluon will gauge predictive performance using evaluation metric: 'MASE'
	This metric's sign has been flipped to adhere to being higher_is_better. The metric score can be multiplied by -1 to get the metric value.
===================================================

Starting training. Start time is 2026-09-07 16:29:08
Models that will be trained: ['SeasonalNaive', 'RecursiveTabular', 'DirectTabular', 'ETS', 'Theta', 'Chronos2', 'Toto2']
Training timeseries model SeasonalNaive. Training for up to 74.7s of the 598.0s of remaining time.
	-1.2169       = Validation score (-MASE)
	0.06    s     = Training runtime
	2.65    s     = Validation (prediction) runtime
Training timeseries model RecursiveTabular. Training for up to 85.0s of the 595.3s of remaining time.
	-0.9339       = Validation score (-MASE)
	10.11   s     = Training runtime
	0.47    s     = Validation (prediction) runtime
Training timeseries model DirectTabular. Training for up to 97.4s of the 584.7s of remaining time.
	-1.3729       = Validation score (-MASE)
	4.45    s     = Training runtime
	0.35    s     = Validation (prediction) runtime
Training timeseries model ETS. Training for up to 116.0s of the 579.8s of remaining time.
	-1.9661       = Validation score (-MASE)
	0.05    s     = Training runtime
	19.25   s     = Validation (prediction) runtime
Training timeseries model Theta. Training for up to 140.1s of the 560.5s of remaining time.
	-2.1331       = Validation score (-MASE)
	0.05    s     = Training runtime
	1.46    s     = Validation (prediction) runtime
Training timeseries model Chronos2. Training for up to 186.3s of the 559.0s of remaining time.
Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads.
Loading weights:   0%|          | 0/92 [00:00<?, ?it/s]
Loading weights: 100%|██████████| 92/92 [00:00<00:00, 2556.28it/s]
	-0.8778       = Validation score (-MASE)
	5.38    s     = Training runtime
	2.13    s     = Validation (prediction) runtime
Training timeseries model Toto2. Training for up to 275.7s of the 551.5s of remaining time.
	-0.9019       = Validation score (-MASE)
	0.99    s     = Training runtime
	0.23    s     = Validation (prediction) runtime
Fitting 1 ensemble(s), in 1 layers.
Training ensemble model WeightedEnsemble. Training for up to 550.2s.
	Ensemble weights: {'Chronos2': 0.43, 'DirectTabular': 0.03, 'ETS': 0.01, 'RecursiveTabular': 0.24, 'SeasonalNaive': 0.01, 'Theta': 0.01, 'Toto2': 0.27}
	-0.8202       = Validation score (-MASE)
	0.78    s     = Training runtime
	26.54   s     = Validation (prediction) runtime
Training complete. Models trained: ['SeasonalNaive', 'RecursiveTabular', 'DirectTabular', 'ETS', 'Theta', 'Chronos2', 'Toto2', 'WeightedEnsemble']
Total runtime: 48.84 s
Best model: WeightedEnsemble
Best model score: -0.8202
<autogluon.timeseries.predictor.TimeSeriesPredictor at 0x7fb13b0270e0>

Here we used the "medium_quality" presets and limited the training time to 10 minutes (600 seconds). The presets define which models AutoGluon will try to fit. For medium_quality presets, these are simple baselines (SeasonalNaive), statistical models (ETS, Theta), tree-based models based on LightGBM (RecursiveTabular, DirectTabular), the pretrained Chronos-2 (small) and Toto-2 (4m) models, and a weighted ensemble combining these. Other available presets for TimeSeriesPredictor are "high_quality" and "best_quality". Higher quality presets will usually produce more accurate forecasts but take longer to train.

Inside fit(), AutoGluon will train as many models as possible within the given time limit. Trained models are then ranked based on their performance on an internal validation set. By default, this validation set is constructed by holding out the last prediction_length timesteps of each time series in train_data.

Generating forecasts with TimeSeriesPredictor.predict

We can now use the fitted TimeSeriesPredictor to forecast the future time series values. By default, AutoGluon will make forecasts using the model that had the best score on the internal validation set. The forecast always includes predictions for the next prediction_length timesteps, starting from the end of each time series in train_data.

predictions = predictor.predict(train_data)
predictions.head()
Model not specified in predict, will default to the model with the best validation score: WeightedEnsemble
Loading weights:   0%|          | 0/92 [00:00<?, ?it/s]
Loading weights: 100%|██████████| 92/92 [00:00<00:00, 2721.37it/s]
mean 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
item_id timestamp
H1 1750-01-30 04:00:00 624.150645 605.961649 612.506850 616.530809 620.321330 624.150645 628.189407 632.428631 637.134213 644.544559
1750-01-30 05:00:00 563.152677 539.788806 548.373343 554.077445 558.762381 563.152677 567.716948 572.842330 579.042555 588.257114
1750-01-30 06:00:00 519.115760 491.190715 501.622459 508.282329 513.805119 519.115760 524.512254 530.124539 537.065973 547.234047
1750-01-30 07:00:00 488.019546 456.226784 467.736234 475.545263 481.754768 488.019546 494.197302 500.674714 508.060897 518.800002
1750-01-30 08:00:00 466.566434 430.806594 443.519784 452.349470 459.329998 466.566434 473.902732 481.412172 489.816880 501.424874

AutoGluon produces a probabilistic forecast: in addition to predicting the mean (expected value) of the time series in the future, models also provide the quantiles of the forecast distribution. The quantile forecasts give us an idea about the range of possible outcomes. For example, if the "0.1" quantile is equal to 500.0, it means that the model predicts a 10% chance that the target value will be below 500.0.

We will now visualize the forecast and the actually observed values for one of the time series in the dataset. We plot the mean forecast, as well as the 10% and 90% quantiles to show the range of potential outcomes.

import matplotlib.pyplot as plt

# TimeSeriesDataFrame can also be loaded directly from a file
test_data = TimeSeriesDataFrame.from_path("https://autogluon.s3.amazonaws.com/datasets/timeseries/m4_hourly_subset/test.csv")

# Plot 4 randomly chosen time series and the respective forecasts
predictor.plot(test_data, predictions, quantile_levels=[0.1, 0.9], max_history_length=200, max_num_item_ids=4);
../../_images/f1345495648c6454aa0ce4b1eb5eb83524d92872f71e5d459ec32b71f8fe0e93.png

Evaluating the performance of different models

We can view the performance of each model AutoGluon has trained via the leaderboard() method. We provide the test data set to the leaderboard function to see how well our fitted models are doing on the unseen test data. The leaderboard also includes the validation scores computed on the internal validation dataset.

Note the test data includes both the forecast horizon (last prediction_length values of each time series) as well as the historical data (all except the last prediction_last values).

In AutoGluon leaderboards, higher scores always correspond to better predictive performance. Therefore our MASE scores are multiplied by -1, such that higher “negative MASE”s correspond to more accurate forecasts.

# The test score is computed using the last
# prediction_length=48 timesteps of each time series in test_data
predictor.leaderboard(test_data)
Additional data provided, testing on additional data. Resulting leaderboard will be sorted according to test score (`score_test`).
Loading weights:   0%|          | 0/92 [00:00<?, ?it/s]
Loading weights: 100%|██████████| 92/92 [00:00<00:00, 2694.83it/s]
model score_test score_val pred_time_test pred_time_val fit_time_marginal fit_order
0 WeightedEnsemble -0.740192 -0.820174 23.387781 26.538855 0.777011 8
1 Chronos2 -0.765236 -0.877750 0.543880 2.125947 5.383997 6
2 RecursiveTabular -0.862797 -0.933874 0.512290 0.467622 10.112311 2
3 Toto2 -0.890937 -0.901884 0.187891 0.229562 0.994984 7
4 SeasonalNaive -1.022854 -1.216909 0.141452 2.648254 0.058856 1
5 DirectTabular -1.648202 -1.372871 0.378366 0.347386 4.451757 3
6 ETS -1.806290 -1.966059 19.957143 19.249576 0.052309 4
7 Theta -1.911989 -2.133107 1.654820 1.456692 0.051912 5

Summary

We used autogluon.timeseries to make probabilistic multi-step forecasts on the M4 Hourly dataset. Check out Forecasting Time Series - In Depth to learn about the advanced capabilities of AutoGluon for time series forecasting.