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 splitting data into 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 on train_data.

    If provided, all time series in data must have length at least prediction_length + (num_val_windows - 1) * val_step_size + 1.

    The names and dtypes of columns and static features in data must match the train_data used 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 the num_val_windows value from training configuration when data=None, otherwise defaults to 1.

    For example, with prediction_length=2, num_val_windows=3, and val_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 x denotes training time steps and y denotes 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 to prediction_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_predictions was set to False when creating the TimeSeriesPredictor.

Returns:

Predictions for each validation window.

  • If model is a str or None: Returns a list of length num_val_windows, where each element contains the predictions for one validation window.

  • If model is a list[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_targets

Return target values aligned with predictions.

evaluate

Evaluate forecast accuracy on a hold-out set.

predict

Generate forecasts for future time steps.