时间序列预测器.预测

TimeSeriesPredictor.predict(data: TimeSeriesDataFrame | DataFrame | Path | str, known_covariates: TimeSeriesDataFrame | DataFrame | Path | str | None = None, model: str | None = None, use_cache: bool = True, random_seed: int | None = 123) TimeSeriesDataFrame[source]

返回给定数据集的分位数和均值预测,从每个时间序列的末尾开始。

Parameters:
  • data (Union[TimeSeriesDataFrame, pd.DataFrame, Path, str]) –

    用于预测的时间序列数据。

    如果在创建预测器时指定了known_covariates_names,则data必须包含known_covariates_names中列出的列,并且协变量值必须与目标时间序列对齐。

    如果用于训练预测器的train_data包含过去的协变量或静态特征,则data也必须包含它们(具有相同的列名和数据类型)。

    如果提供的数据是pandas DataFrame的实例,AutoGluon将尝试自动将其转换为TimeSeriesDataFrame

  • known_covariates (Union[TimeSeriesDataFrame, pd.DataFrame, Path, str], optional) –

    如果在创建预测器时指定了known_covariates_names,则有必要在预测范围内为每个时间序列提供已知协变量的值。即:

    • 列必须包括known_covariates_names中列出的所有列

    • item_id索引必须包括data中存在的所有项目ID

    • timestamp索引必须包括从data中每个时间序列的末尾开始的prediction_length多个时间步长的未来值

    请参见下面的示例。

  • model (str, optional) – 您希望用于预测的模型名称。默认情况下,将使用训练期间表现最佳的模型(具有最高验证分数)。

  • random_seed (int or None, default = 123) – If provided, fixes the seed of the random number generator for all models. This guarantees reproducible results for most models (except those trained on GPU because of the non-determinism of GPU operations).

  • use_cache (bool, default = True) – If True, will attempt to use the cached predictions. If False, cached predictions will be ignored. This argument is ignored if cache_predictions was set to False when creating the TimeSeriesPredictor.

示例

>>> print(data)
                    target  promotion  price
item_id timestamp
A       2020-01-05      20          0   19.9
        2020-01-06      40          1    9.9
        2020-01-07      32          0   15.0
B       2020-03-01      13          0    5.0
        2020-03-02      44          1    2.9
        2020-03-03      72          1    2.9
>>> predictor = TimeSeriesPredictor(prediction_length=2, known_covariates_names=["promotion", "price"]).fit(data)
>>> print(future_known_covariates)
                    promotion  price
item_id timestamp
A       2020-01-08          1   12.9
        2020-01-09          1   12.9
B       2020-03-04          0    5.0
        2020-03-05          0    7.0
>>> predictor.predict(data, known_covariates=future_known_covariates)
                      mean
item_id timestamp
A       2020-01-08    30.2
        2020-01-09    27.0
B       2020-03-04    17.1
        2020-03-05     8.3