CrossEntropy#

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

Bases: MultiHorizonMetric

Cross entropy loss for classification.

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(y_pred)

Convert network prediction into a point prediction.

to_quantiles(y_pred[, quantiles])

Convert network prediction into a quantile prediction.

loss(y_pred, target)[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(y_pred: Tensor) Tensor[source]#

Convert network prediction into a point prediction.

Returns best label

Parameters

y_pred – prediction output of network

Returns

point prediction

Return type

torch.Tensor

to_quantiles(y_pred: Tensor, quantiles: Optional[List[float]] = None) Tensor[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