Skip to main content
Use exogenous regressors for training and predicting

Data setup

Use existing exogenous features

In mlforecast the required columns are the series identifier, time and target. Any extra columns you have, like static_0 and product_id here are considered to be static and are replicated when constructing the features for the next timestamp. You can disable this by passing static_features to MLForecast.preprocess or MLForecast.fit, which will only keep the columns you define there as static. Keep in mind that all features in your input dataframe will be used for training, so you’ll have to provide the future values of exogenous features to MLForecast.predict through the X_df argument. Consider the following example. Suppose that we have a prices catalog for each id and date.
And that you have already merged these prices into your series dataframe.
This dataframe will be passed to MLForecast.fit (or MLForecast.preprocess). However, since the price is dynamic we have to tell that method that only static_0 and product_id are static.
The features used for training are stored in MLForecast.ts.features_order_. As you can see price was used for training.
So in order to update the price in each timestep we just call MLForecast.predict with our forecast horizon and pass the prices catalog through X_df.

Generating exogenous features

Nixtla provides some utilities to generate exogenous features for both training and forecasting such as statsforecast’s mstl_decomposition or the transform_exog function. We also have utilsforecast’s fourier function, which we’ll demonstrate here.
Suppose you start with some data like the one above where we have a couple of static features.
Now we’d like to add some fourier terms to model the seasonality. We can do that with the following:
This provides an extended training dataset.
Along with the future values of the features.
We can now train using only these features (and the static ones).
And provide the future values to the predict method.