Skip to main content
Train one model to predict each step of the forecasting horizon
By default mlforecast uses the recursive strategy, i.e. a model is trained to predict the next value and if we’re predicting several values we do it one at a time and then use the model’s predictions as the new target, recompute the features and predict the next step. There’s another approach called direct forecasting where if we want to predict 10 steps ahead we train 10 different models, where each model is trained to predict the value at each specific step, i.e. one model predicts the next value, another one predicts the value two steps ahead and so on. This can be very time consuming but can also provide better results. mlforecast provides two ways to use direct forecasting:
  1. max_horizon: Train models for all horizons from 1 to max_horizon. For example, max_horizon=10 trains 10 models (for steps 1, 2, 3, …, 10).
  2. horizons: Train models only for specific horizons. For example, horizons=[7, 14] trains only 2 models (for steps 7 and 14), which reduces computational cost when you only need predictions at certain steps.
Both parameters are mutually exclusive - you can use one or the other, but not both.

Setup

Data

We will use four random series from the M4 dataset

Using max_horizon (all horizons)

Using horizons (specific horizons only)

When you only need predictions at specific time steps (e.g., weekly and bi-weekly forecasts), you can use the horizons parameter to train models only for those steps. This significantly reduces computational cost. For example, if you have hourly data and only need 12-hour and 24-hour ahead predictions:
Notice that with horizons=[12, 24], the output only contains 2 predictions per series (at steps 12 and 24), not 24. This is the sparse output behavior - you only get predictions for the horizons you trained.

Partial predictions

If you call predict(h=N) where N is less than some of your trained horizons, you’ll only get predictions for horizons up to N:

Cross-validation with specific horizons

The horizons parameter also works with cross_validation:

Summary

Key points: - max_horizon and horizons are mutually exclusive - With horizons, the output only contains predictions for the specified horizons (sparse output) - Both direct forecasting approaches work with cross_validation and exogenous features