CompositeMetric

class pytorch_forecasting.metrics.CompositeMetric(metrics: List[torchmetrics.metric.Metric] = [], weights: Optional[List[float]] = None)[source]

Bases: torchmetrics.metric.Metric

Metric that combines multiple metrics.

Metric does not have to be called explicitly but is automatically created when adding and multiplying metrics with each other.

Example

composite_metric = SMAPE() + 0.4 * MAE()
Parameters
  • metrics (List[LightningMetric], optional) – list of metrics to combine. Defaults to [].

  • weights (List[float], optional) – list of weights / multipliers for weights. Defaults to 1.0 for all metrics.

Methods

compute()

Get metric

to_prediction(y_pred, **kwargs)

Convert network prediction into a point prediction.

to_quantiles(y_pred, **kwargs)

Convert network prediction into a quantile prediction.

update(y_pred, y_actual)

Update composite metric

compute() torch.Tensor[source]

Get metric

Returns

metric

Return type

torch.Tensor

to_prediction(y_pred: torch.Tensor, **kwargs) torch.Tensor[source]

Convert network prediction into a point prediction.

Will use first metric in metrics attribute to calculate result.

Parameters
  • y_pred – prediction output of network

  • **kwargs – parameters to first metric to_prediction method

Returns

point prediction

Return type

torch.Tensor

to_quantiles(y_pred: torch.Tensor, **kwargs) torch.Tensor[source]

Convert network prediction into a quantile prediction.

Will use first metric in metrics attribute to calculate result.

Parameters
  • y_pred – prediction output of network

  • **kwargs – parameters to first metric’s to_quantiles() method

Returns

prediction quantiles

Return type

torch.Tensor

update(y_pred: torch.Tensor, y_actual: torch.Tensor)[source]

Update composite metric

Parameters
  • y_pred – network output

  • y_actual – actual values

Returns

metric value on which backpropagation can be applied

Return type

torch.Tensor