Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Sktime Pytorch forecasting Baseline

From Leeroopedia


Knowledge Sources
Domains Time_Series, Forecasting, Deep_Learning
Last Updated 2026-02-08 08:00 GMT

Overview

Baseline is a simple last-value-repeat forecasting model that uses the last known encoder target value as the prediction for all future time steps.

Description

Baseline extends BaseModel and implements the simplest possible forecasting strategy: it takes the last observed value from the encoder target and repeats it across the entire prediction horizon. It supports both single-target and multi-target scenarios. The model requires no trainable parameters and serves as a reference point for evaluating the performance of more sophisticated models. It also provides to_prediction and to_quantiles convenience methods.

Usage

Use Baseline as a naive benchmark model to establish a performance floor when developing and evaluating forecasting models. It is useful for sanity-checking data pipelines and for comparing against learned models to quantify the value of model complexity.

Code Reference

Source Location

Signature

class Baseline(BaseModel):
    def forward(self, x: dict[str, torch.Tensor]) -> dict[str, torch.Tensor]:
    def forward_one_target(
        self,
        encoder_lengths: torch.Tensor,
        decoder_lengths: torch.Tensor,
        encoder_target: torch.Tensor,
    ):
    def to_prediction(self, out: dict[str, Any], use_metric: bool = True, **kwargs):
    def to_quantiles(self, out: dict[str, Any], use_metric: bool = True, **kwargs):

Import

from pytorch_forecasting.models.baseline import Baseline

I/O Contract

Inputs

forward

Name Type Required Description
x dict[str, torch.Tensor] Yes Network input dictionary containing "encoder_target" (torch.Tensor or list of torch.Tensor), "encoder_lengths" (torch.Tensor), and "decoder_lengths" (torch.Tensor).

forward_one_target

Name Type Required Description
encoder_lengths torch.Tensor Yes Tensor of encoder sequence lengths per sample in the batch.
decoder_lengths torch.Tensor Yes Tensor of decoder (prediction) sequence lengths per sample in the batch.
encoder_target torch.Tensor Yes Encoder target values tensor of shape (batch_size, max_encoder_length).

to_prediction

Name Type Required Description
out dict[str, Any] Yes Network output dictionary (from forward).
use_metric bool No Whether to use metric for conversion. Defaults to True.

to_quantiles

Name Type Required Description
out dict[str, Any] Yes Network output dictionary (from forward).
use_metric bool No Whether to use metric for conversion. Defaults to True.

Outputs

forward

Name Type Description
output dict[str, torch.Tensor] Network output dictionary with "prediction" key containing the repeated last-value tensor of shape (batch_size, max_prediction_length) or a list thereof for multi-target.

forward_one_target

Name Type Description
prediction torch.Tensor Prediction tensor of shape (batch_size, max_prediction_length) where each row is the last encoder value repeated.

to_prediction

Name Type Description
prediction torch.Tensor The raw prediction tensor from the output.

to_quantiles

Name Type Description
quantiles torch.Tensor The prediction tensor with an extra trailing dimension: (batch_size, max_prediction_length, 1).

Usage Examples

import torch
from pytorch_forecasting.models.baseline import Baseline
from pytorch_forecasting.metrics import MAE

# Generate predictions using a dataloader
model = Baseline()
predictions = model.predict(dataloader)

# Calculate baseline MAE performance
metric = MAE()
for x, y in dataloader:
    metric.update(model(x), y)
result = metric.compute()

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment