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 Point Metrics

From Leeroopedia
Revision as of 16:42, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Sktime_Pytorch_forecasting_Point_Metrics.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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

Overview

A collection of point forecast metrics for evaluating single-point-per-timestep predictions in time series forecasting.

Description

The Point Metrics module provides a suite of loss functions and evaluation metrics for point forecasting tasks. Each metric class extends MultiHorizonMetric and implements a loss method that computes element-wise error between predictions and targets. The module includes standard regression losses (MAE, RMSE, MASE), percentage-based errors (SMAPE, MAPE), distributional losses (PoissonLoss, TweedieLoss), and a classification loss (CrossEntropy).

All metrics support multi-horizon evaluation and can convert raw network outputs to point predictions and quantile predictions through the inherited to_prediction and to_quantiles methods.

Usage

Use these metrics as loss functions during model training or as evaluation metrics during validation and testing. They are passed to model constructors via the loss or logging_metrics parameters and are suitable for any point forecasting task within the pytorch-forecasting framework.

Code Reference

Source Location

Signatures

PoissonLoss

class PoissonLoss(MultiHorizonMetric):
    def loss(self, y_pred: dict[str, torch.Tensor], target: torch.Tensor) -> torch.Tensor
    def to_prediction(self, out: dict[str, torch.Tensor])
    def to_quantiles(self, out: dict[str, torch.Tensor], quantiles=None)

SMAPE

class SMAPE(MultiHorizonMetric):
    def loss(self, y_pred, target)

MAPE

class MAPE(MultiHorizonMetric):
    def loss(self, y_pred, target)

MAE

class MAE(MultiHorizonMetric):
    def loss(self, y_pred, target)

CrossEntropy

class CrossEntropy(MultiHorizonMetric):
    def loss(self, y_pred, target)
    def to_prediction(self, y_pred: torch.Tensor) -> torch.Tensor
    def to_quantiles(self, y_pred: torch.Tensor, quantiles: list[float] = None) -> torch.Tensor

RMSE

class RMSE(MultiHorizonMetric):
    def __init__(self, reduction="sqrt-mean", **kwargs)
    def loss(self, y_pred: dict[str, torch.Tensor], target)

MASE

class MASE(MultiHorizonMetric):
    def update(self, y_pred, target, encoder_target, encoder_lengths=None) -> torch.Tensor
    def loss(self, y_pred, target, scaling)
    @staticmethod
    def calculate_scaling(target, lengths, encoder_target, encoder_lengths)

TweedieLoss

class TweedieLoss(MultiHorizonMetric):
    def __init__(self, reduction="mean", p: float = 1.5, **kwargs)
    def to_prediction(self, out: dict[str, torch.Tensor])
    def loss(self, y_pred, y_true)

Import

from pytorch_forecasting.metrics.point import PoissonLoss, SMAPE, MAPE, MAE, CrossEntropy, RMSE, MASE, TweedieLoss

I/O Contract

Inputs

Name Type Required Description
y_pred dict[str, torch.Tensor] or torch.Tensor Yes Network output containing predictions
target torch.Tensor Yes Ground truth target values
encoder_target torch.Tensor or rnn.PackedSequence No Historic actual values (MASE only)
encoder_lengths torch.Tensor No Lengths of encoder sequences (MASE only)
p float No Tweedie variance power in [1, 2) (TweedieLoss only, default 1.5)
reduction str No Reduction method: "mean", "sqrt-mean", or "none"
quantiles list[float] No Quantile levels for to_quantiles conversion

Outputs

Name Type Description
loss torch.Tensor Element-wise loss values with shape matching the target
prediction torch.Tensor Point prediction from to_prediction (may apply exp transform for PoissonLoss/TweedieLoss)
quantiles torch.Tensor Quantile predictions from to_quantiles

Usage Examples

from pytorch_forecasting.metrics.point import MAE, SMAPE, RMSE, TweedieLoss

# Use MAE as a training loss
mae_loss = MAE()

# Use RMSE with its default sqrt-mean reduction
rmse_loss = RMSE()

# Use SMAPE for percentage-based evaluation
smape_metric = SMAPE()

# Use TweedieLoss for insurance/count data with custom p parameter
tweedie_loss = TweedieLoss(p=1.8)

# Pass metrics to a model
model = SomeForecaster(
    loss=mae_loss,
    logging_metrics=[smape_metric, rmse_loss],
)

Related Pages

Page Connections

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