基线#

class pytorch_forecasting.models.baseline.Baseline(dataset_parameters: Dict[str, Any] = None, log_interval: int | float = -1, log_val_interval: int | float = None, learning_rate: float | List[float] = 0.001, log_gradient_flow: bool = False, loss: 指标 = SMAPE(), logging_metrics: ModuleList = ModuleList(), reduce_on_plateau_patience: int = 1000, reduce_on_plateau_reduction: float = 2.0, reduce_on_plateau_min_lr: float = 1e-05, weight_decay: float = 0.0, optimizer_params: Dict[str, Any] = None, monotone_constraints: Dict[str, int] = {}, output_transformer: Callable = None, optimizer='adam')[来源]#

基础: BaseModel

基线模型,使用最后已知的目标值进行预测。

示例:

from pytorch_forecasting import BaseModel, MAE

# generating predictions
predictions = Baseline().predict(dataloader)

# calculate baseline performance in terms of mean absolute error (MAE)
metric = MAE()
model = Baseline()
for x, y in dataloader:
    metric.update(model(x), y)

metric.compute()

用于继承的时间序列预测的基础模型

Parameters:
  • log_interval (Union[int, float], optional) – 预测将被记录的批次数。如果 < 1.0,则每个批次会记录多个条目。默认值为 -1。

  • log_val_interval (Union[int, float], optional) – 预测验证结果记录的批次数。默认为 None/log_interval。

  • learning_rate (float, 可选) – 学习率。默认为 1e-3。

  • log_gradient_flow (bool) – 如果要记录梯度流,这会耗费时间,应仅用于诊断训练失败。默认为 False。

  • 损失 (指标, 可选) – 要优化的指标,也可以是指标的列表。默认为 SMAPE()。

  • logging_metrics (nn.ModuleList[MultiHorizonMetric]) – 在训练期间记录的度量列表。默认为[]。

  • reduce_on_plateau_patience (int) – 在此之后学习率减少10倍的耐心。默认为1000

  • reduce_on_plateau_reduction (float) – 当遇到平台期时,学习率的减少。默认值为 2.0。

  • reduce_on_plateau_min_lr (float) – 降至平台学习率调度器的最小学习率。默认值为 1e-5

  • weight_decay (float) – 权重衰减。默认为 0.0。

  • optimizer_params (字典[字符串, 任意类型]) – 优化器的附加参数。默认为 {}.

  • monotone_constraints (Dict[str, int]) – 用于连续解码器变量的单调性约束字典 将位置映射到约束(例如,"0"表示第一个位置)(-1表示负约束,+1表示正约束, 较大的数字对约束相对于损失增加更多的权重,但通常是不必要的)。 这个约束显著减慢训练速度。默认值为 {}。

  • output_transformer (可调用对象) – 转换器,将网络输出转换为预测空间。默认为 None,相当于 lambda out: out["prediction"]

  • optimizer (str) – 优化器,“ranger”、“sgd”、“adam”、“adamw”或torch.optim中的优化器类名或pytorch_optimizer。可以传递一个类或函数,该类或函数将参数作为第一个参数,并可选地带有lr参数(也可以有weight_decay)。默认为“adam”。

方法

forward(x)

网络前向传播。

forward_one_target(encoder_lengths, ...)

to_prediction(out[, use_metric])

使用损失指标将输出转换为预测。

to_quantiles(out[, use_metric])

使用损失指标将输出转换为分位数。

forward(x: Dict[str, Tensor]) Dict[str, Tensor][来源]#

网络前向传播。

Parameters:

x (字典[字符串, torch.Tensor]) – 网络输入

Returns:

网络输出

Return type:

字典[str, torch.Tensor]

to_prediction(out: Dict[str, Any], use_metric: bool = True, **kwargs)[来源]#

使用损失指标将输出转换为预测。

Parameters:
  • out (字典[字符串, 任意]) – 网络的输出,其中“预测”已通过 transform_output() 转换

  • use_metric (bool) – 是否使用指标进行转换,如果为 False,则简单地对 out["prediction"] 进行平均

  • **kwargs – 传递给度量 to_quantiles 方法的参数

Returns:

预测形状为 batch_size x timesteps

Return type:

torch.Tensor

to_quantiles(out: Dict[str, Any], use_metric: bool = True, **kwargs)[来源]#

使用损失指标将输出转换为分位数。

Parameters:
  • out (字典[字符串, 任何]) – 网络的输出,其中“预测”已通过 transform_output() 进行了转换

  • use_metric (bool) – 是否使用指标进行转换,如果为 False,简单地对 out["prediction"] 取分位数

  • **kwargs – 传递给指标 to_quantiles 方法的参数

Returns:

形状为 batch_size x timesteps x n_quantiles 的分位数

Return type:

torch.Tensor