PoissonLoss#

class pytorch_forecasting.metrics.point.PoissonLoss(reduction: str = 'mean', **kwargs)[source]#

Bases: MultiHorizonMetric

Poisson loss for count data.

The loss will take the exponential of the network output before it is returned as prediction. Target normalizer should therefore have no “reverse” transformation, e.g. for the TimeSeriesDataSet initialization, one could use:

from pytorch_forecasting import TimeSeriesDataSet, EncoderNormalizer

dataset = TimeSeriesDataSet(
    target_normalizer=EncoderNormalizer(transformation=dict(forward=torch.log1p))
)

Note that in this example, the data is log1p-transformed before normalized but not re-transformed. The PoissonLoss applies this “exp”-re-transformation on the network output after it has been de-normalized. The result is the model prediction.

Initialize metric

Parameters:
  • name (str) – metric name. Defaults to class name.

  • quantiles (List[float], optional) – quantiles for probability range. Defaults to None.

  • reduction (str, optional) – Reduction, “none”, “mean” or “sqrt-mean”. Defaults to “mean”.

Methods

loss(y_pred, target)

Calculate loss without reduction.

to_prediction(out)

Convert network prediction into a point prediction.

to_quantiles(out[, quantiles])

Convert network prediction into a quantile prediction.

loss(y_pred: Dict[str, Tensor], target: Tensor) Tensor[source]#

Calculate loss without reduction. Override in derived classes

Parameters:
  • y_pred – network output

  • y_actual – actual values

Returns:

loss/metric as a single number for backpropagation

Return type:

torch.Tensor

to_prediction(out: Dict[str, Tensor])[source]#

Convert network prediction into a point prediction.

Parameters:

y_pred – prediction output of network

Returns:

point prediction

Return type:

torch.Tensor

to_quantiles(out: Dict[str, Tensor], quantiles=None)[source]#

Convert network prediction into a quantile prediction.

Parameters:
  • y_pred – prediction output of network

  • quantiles (List[float], optional) – quantiles for probability range. Defaults to quantiles as as defined in the class initialization.

Returns:

prediction quantiles

Return type:

torch.Tensor