The model is trained each time before making the predictions, in this way, the model use all the information available so far. It is a variation of the standard cross-validation but, instead of making a random distribution of the observations, the training set is increased sequentially, maintaining the temporal order of the data.
Backtesting without refit
After an initial train, the model is used sequentially without updating it and following the temporal order of the data. This strategy has the advantage of being much faster since the model is only trained once. However, the model does not incorporate the latest information available so it may lose predictive capacity over time.
# Backtest forecaster# ==============================================================================n_backtest=36*3# Last 9 years are used for backtestdata_train=data[:-n_backtest]data_test=data[-n_backtest:]forecaster=ForecasterAutoreg(regressor=RandomForestRegressor(random_state=123),lags=15)metric,predictions_backtest=backtesting_forecaster(forecaster=forecaster,y=data,initial_train_size=len(data_train),steps=10,metric='mean_squared_error',refit=True,verbose=True)
Information of backtesting process
----------------------------------
Number of observations used for initial training: 96
Number of observations used for backtesting: 108
Number of folds: 11
Number of steps per fold: 10
Last fold only includes 8 observations.
Data partition in fold: 0
Training: 1991-07-01 00:00:00 -- 1999-06-01 00:00:00
Validation: 1999-07-01 00:00:00 -- 2000-04-01 00:00:00
Data partition in fold: 1
Training: 1991-07-01 00:00:00 -- 2000-04-01 00:00:00
Validation: 2000-05-01 00:00:00 -- 2001-02-01 00:00:00
Data partition in fold: 2
Training: 1991-07-01 00:00:00 -- 2001-02-01 00:00:00
Validation: 2001-03-01 00:00:00 -- 2001-12-01 00:00:00
Data partition in fold: 3
Training: 1991-07-01 00:00:00 -- 2001-12-01 00:00:00
Validation: 2002-01-01 00:00:00 -- 2002-10-01 00:00:00
Data partition in fold: 4
Training: 1991-07-01 00:00:00 -- 2002-10-01 00:00:00
Validation: 2002-11-01 00:00:00 -- 2003-08-01 00:00:00
Data partition in fold: 5
Training: 1991-07-01 00:00:00 -- 2003-08-01 00:00:00
Validation: 2003-09-01 00:00:00 -- 2004-06-01 00:00:00
Data partition in fold: 6
Training: 1991-07-01 00:00:00 -- 2004-06-01 00:00:00
Validation: 2004-07-01 00:00:00 -- 2005-04-01 00:00:00
Data partition in fold: 7
Training: 1991-07-01 00:00:00 -- 2005-04-01 00:00:00
Validation: 2005-05-01 00:00:00 -- 2006-02-01 00:00:00
Data partition in fold: 8
Training: 1991-07-01 00:00:00 -- 2006-02-01 00:00:00
Validation: 2006-03-01 00:00:00 -- 2006-12-01 00:00:00
Data partition in fold: 9
Training: 1991-07-01 00:00:00 -- 2006-12-01 00:00:00
Validation: 2007-01-01 00:00:00 -- 2007-10-01 00:00:00
Data partition in fold: 10
Training: 1991-07-01 00:00:00 -- 2007-10-01 00:00:00
Validation: 2007-11-01 00:00:00 -- 2008-06-01 00:00:00