Skip to main content
Customize the training procedure for your models
mlforecast abstracts away most of the training details, which is useful for iterating quickly. However, sometimes you want more control over the fit parameters, the data that goes into the model, etc. This guide shows how you can train a model in a specific way and then giving it back to mlforecast to produce forecasts with it.

Data setup

Creating forecast object

Suppose we want to train a linear regression with the default settings.

Generate training set

Use MLForecast.preprocess to generate the training data.

Regular training

Since we don’t want to do anything special in our training process for the linear regression, we can just call MLForecast.fit_models
This has trained the linear regression model and is now available in the MLForecast.models_ attribute.

Custom training

Now suppose you also want to train a LightGBM model on the same data, but treating the day of the week as a categorical feature and logging the train loss.

Computing forecasts

Now we just assign this model to the MLForecast.models_ dictionary. Note that you can assign as many models as you want.
And now when calling MLForecast.predict, mlforecast will use those models to compute the forecasts.