Skip to main content
Get access to the input features and predictions in each forecasting horizon
If you want to do something to the input before predicting or something to the output before it gets used to update the target (and thus the next features that rely on lags), you can pass a function to run at any of these times. Here are a couple of examples:

Before predicting

Inspecting the input

We can define a function that displays our input dataframe before predicting.
And now we can pass this function to the before_predict_callback argument of MLForecast.predict.
unique_idlag1lag2
0id_04.155933.000028
unique_idlag1lag2
0id_05.2502054.15593
unique_iddsLGBMRegressor
0id_02000-08-105.250205
1id_02000-08-116.241739

Saving the input features

Saving the features that are sent as input to the model in each timestamp can be helpful, for example to estimate SHAP values. This can be easily achieved with the SaveFeatures callback.
Once we’ve called predict we can just retrieve the features.
unique_idlag1
0id_04.155930
1id_05.281643

After predicting

When predicting with the recursive strategy (the default) the predictions for each timestamp are used to update the target and recompute the features. If you want to do something to these predictions before that happens you can use the after_predict_callback argument of MLForecast.predict.

Increasing predictions values

Suppose we know that our model always underestimates and we want to prevent that from happening by making our predictions 10% higher. We can achieve that with the following: