Skip to main content
Compute transformations on your exogenous features for MLForecast
The MLForecast class allows you to compute lag transformations on your target, however, sometimes you want to also compute transformations on your dynamic exogenous features. This guide shows you how to accomplish that.

Data setup

Suppose that you have some series along with their prices for each id and date and you want to compute forecasts for the next 7 days. Since the price is a dynamic feature you have to provide the future values through X_df in MLForecast.predict. If you want to use not only the price but the lag7 of the price and the expanding mean of the lag1 for example, you can compute them before training, merge them with your series and then provide the future values through X_df. Consider the following example.

Computing the transformations

You can now merge this with your original series
You can then define your forecast object. Note that you can still compute lag features based on the target as you normally would.
It’s important to note that the dropna argument only considers the null values generated by the lag features based on the target. If you want to drop all rows containing null values you have to do that in your original series.
You can now train the model.
And predict using the prices. Note that you can provide the dataframe with the full history and mlforecast will filter the required dates for the forecasting horizon.
In this example we have prices for the next 7 days, if you try to forecast a longer horizon you’ll get an error.