Since version 0.4.0, skforecast allows using scikit-learn pipelines as regressors. This is useful since, many machine learning models, need specific data preprocessing transformations. For example, linear models with Ridge or Lasso regularization benefits from features been scaled.
⚠ WARNING:
Version 0.4 does not allow including ColumnTransformer in the pipeline used as regressor, so if the preprocessing transformations only apply to some specific columns, they have to be applied on the data set before training the model. A more detailed example can be found here.
When performing grid search over a sklearn pipeline, the name of the parameters is preceded by the name of the model.
1 2 3 4 5 6 7 8 910111213141516171819202122232425
pipe=make_pipeline(StandardScaler(),Ridge())forecaster=ForecasterAutoreg(regressor=pipe,lags=10# This value will be replaced in the grid search)# Regressor's hyperparametersparam_grid={'ridge__alpha':np.logspace(-3,5,10)}# Lags used as predictorslags_grid=[5,24,[1,2,3,23,24]]results_grid=grid_search_forecaster(forecaster=forecaster,y=data['y'],exog=data[['exog_1','exog_2']],param_grid=param_grid,lags_grid=lags_grid,steps=5,metric='mean_absolute_error',refit=False,initial_train_size=len(data.loc[:'2000-04-01']),return_best=True,verbose=False)