QuantileLoss

class pytorch_forecasting.metrics.QuantileLoss(quantiles: List[float] = [0.02, 0.1, 0.25, 0.5, 0.75, 0.9, 0.98], **kwargs)[source]

Bases: pytorch_forecasting.metrics.MultiHorizonMetric

Quantile loss, i.e. a quantile of q=0.5 will give half of the mean absolute error as it is calcualted as

Defined as max(q * (y-y_pred), (1-q) * (y_pred-y))

Quantile loss

Parameters

quantiles – quantiles for metric

Methods

loss(y_pred, target)

Calculate loss without reduction.

to_prediction(y_pred)

Convert network prediction into a point prediction.

to_quantiles(y_pred)

Convert network prediction into a quantile prediction.

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

Convert network prediction into a quantile prediction.

Parameters

y_pred – prediction output of network

Returns

prediction quantiles

Return type

torch.Tensor