TimeSeriesPredictor.backtest_predictions¶
- TimeSeriesPredictor.backtest_predictions(data: TimeSeriesDataFrame | None = None, *, model: str | None = None, num_val_windows: int | None = None, val_step_size: int | None = None, use_cache: bool = True) list[TimeSeriesDataFrame][source]¶
- TimeSeriesPredictor.backtest_predictions(data: TimeSeriesDataFrame | None = None, *, model: list[str], num_val_windows: int | None = None, val_step_size: int | None = None, use_cache: bool = True) dict[str, list[TimeSeriesDataFrame]]
Return predictions for multiple validation windows.
When
data=None, returns the predictions that were saved during training. Otherwise, generates new predictions by splittingdatainto multiple windows using an expanding window strategy.The corresponding target values for each window can be obtained using
backtest_targets().- Parameters:
data (TimeSeriesDataFrame, optional) –
Time series data to generate predictions for. If
None, returns the predictions that were saved during training ontrain_data.If provided, all time series in
datamust have length at leastprediction_length + (num_val_windows - 1) * val_step_size + 1.The names and dtypes of columns and static features in
datamust match thetrain_dataused to train the predictor.model (str, list[str], or None, default = None) –
Name of the model(s) to generate predictions with. By default, the best model during training (with highest validation score) will be used.
If
str: Returns predictions for a single model as a list.If
list[str]: Returns predictions for multiple models as a dict mapping model names to lists.If
None: Uses the best model.
num_val_windows (int, optional) –
Number of validation windows to generate. If
None, uses thenum_val_windowsvalue from training configuration whendata=None, otherwise defaults to 1.For example, with
prediction_length=2,num_val_windows=3, andval_step_size=1, the validation windows are:|-------------------| | x x x x x y y - - | | x x x x x x y y - | | x x x x x x x y y |
where
xdenotes training time steps andydenotes validation time steps for each window.val_step_size (int, optional) – Number of time steps between the start of consecutive validation windows. If
None, defaults toprediction_length.use_cache (bool, default = True) – If True, will attempt to use cached predictions. If False, cached predictions will be ignored. This argument is ignored if
cache_predictionswas set to False when creating theTimeSeriesPredictor.
- Returns:
Predictions for each validation window.
If
modelis astrorNone: Returns a list of lengthnum_val_windows, where each element contains the predictions for one validation window.If
modelis alist[str]: Returns a dict mapping each model name to a list of predictions for each validation window.
- Return type:
list[TimeSeriesDataFrame] or dict[str, list[TimeSeriesDataFrame]]
Examples
Make predictions on new data with the best model
>>> predictor.backtest_predictions(test_data, num_val_windows=2)
Load validation predictions for all models that were saved during training
>>> predictor.backtest_predictions(model=predictor.model_names())
See also
backtest_targetsReturn target values aligned with predictions.
evaluateEvaluate forecast accuracy on a hold-out set.
predictGenerate forecasts for future time steps.