Skip to main content
Tune your forecasting models

Imports

Data setup

Optimization

Default optimization

We have default search spaces for some models and we can define default features to look for based on the length of the seasonal period of your data. For this example we’ll use hourly data, for which we’ll set 24 (one day) as the season length.
We can now use these models to predict
unique_iddslgbridge
0H1701680.534943604.140123
1H1702599.038307523.364874
2H1703572.808421479.174481
3H1704564.573783444.540062
4H1705543.046026419.987657
And evaluate them
lgbridge
SMAPE18.7820.00
MASE5.071.29
OWA1.570.81

Tuning model parameters

You can provide your own model with its search space to perform the optimization. The search space should be a function that takes an optuna trial and returns the model parameters.
my_lgb
SMAPE18.67
MASE4.79
OWA1.51

Tuning scikit-learn pipelines

We internally use BaseEstimator.set_params for each configuration, so if you’re using a scikit-learn pipeline you can tune its parameters as you normally would with scikit-learn’s searches.
ridge
SMAPE18.50
MASE1.24
OWA0.76

Tuning features

The MLForecast class defines the features to build in its constructor. You can tune the features by providing a function through the init_config argument, which will take an optuna trial and produce a configuration to pass to the MLForecast constructor.
AutoRidge
SMAPE13.31
MASE1.67
OWA0.71

Tuning fit parameters

The MLForecast.fit method takes some arguments that could improve the forecasting performance of your models, such as dropna and static_features. If you want to tune those you can provide a function to the fit_config argument.
AutoLightGBM
SMAPE18.78
MASE5.07
OWA1.57

Accessing the optimization results

After the process has finished the results are available under the results_ attribute of the AutoMLForecast object. There will be one result per model and the best configuration can be found under the config user attribute.

Individual models

There is one optimization process per model. This is because different models can make use of different features. So after the optimization process is done for each model the best configuration is used to retrain the model using all of the data. These final models are MLForecast objects and are saved in the models_ attribute.

Saving

You can use the AutoMLForecast.save method to save the best models found. This produces one directory per model.
Since each model is an MLForecast object you can load it by itself.