Metrics#

Multiple metrics have been implemented to ease adaptation.

In particular, these metrics can be applied to the multi-horizon forecasting problem, i.e. can take tensors that are not only of shape n_samples but also n_samples x prediction_horizon or even n_samples x prediction_horizon x n_outputs, where n_outputs could be the number of forecasted quantiles.

Metrics can be easily combined by addition, e.g.

from pytorch_forecasting.metrics import SMAPE, MAE

composite_metric = SMAPE() + 1e-4 * MAE()

Such composite metrics are useful when training because they can reduce outliers in other metrics. In the example, SMAPE is mostly optimized, while large outliers in MAE are avoided.

Further, one can modify a loss metric to reduce a mean prediction bias, i.e. ensure that predictions add up. For example:

from pytorch_forecasting.metrics import MAE, AggregationMetric

composite_metric = MAE() + AggregationMetric(metric=MAE())

Here we add to MAE an additional loss. This additional loss is the MAE calculated on the mean predictions and actuals. We can also use other metrics such as SMAPE to ensure aggregated results are unbiased in that metric. One important point to keep in mind is that this metric is calculated across samples, i.e. it will vary depending on the batch size. In particular, errors tend to average out with increased batch sizes.

Details#

See the API documentation for further details on available metrics:

pytorch_forecasting.metrics._distributions_pkg._beta._beta_distribution_loss_pkg.BetaDistributionLoss_pkg()

Beta distribution loss metric for distribution forecasts.

pytorch_forecasting.metrics._distributions_pkg._implicit_quantile_network._implicit_quantile_network_distribution_loss_pkg.ImplicitQuantileNetworkDistributionLoss_pkg()

Implicit quantile network distribution loss metric for distribution forecasts.

pytorch_forecasting.metrics._distributions_pkg._log_normal._log_normal_distribution_loss_pkg.LogNormalDistributionLoss_pkg()

Log-normal distribution loss metric for distribution forecasts.

pytorch_forecasting.metrics._distributions_pkg._mqf2._mqf2_distribution_loss_pkg.MQF2DistributionLoss_pkg()

MQF2 distribution loss metric for distribution forecasts.

pytorch_forecasting.metrics._distributions_pkg._multivariate_normal._multivariate_normal_distribution_loss_pkg.MultivariateNormalDistributionLoss_pkg()

Multivariate normal distribution loss metric for distribution forecasts.

pytorch_forecasting.metrics._distributions_pkg._negative_binomial._negative_binomial_distribution_loss_pkg.NegativeBinomialDistributionLoss_pkg()

Negative binomial distribution loss metric for distribution forecasts.

pytorch_forecasting.metrics._distributions_pkg._normal._normal_distribution_loss_pkg.NormalDistributionLoss_pkg()

Normal distribution loss metric for distribution forecasts.

pytorch_forecasting.metrics._point_pkg._cross_entropy._cross_entropy_pkg.CrossEntropy_pkg()

Package container for CrossEntropyLoss - a loss function for categorical targets.

pytorch_forecasting.metrics._point_pkg._mae._mae_pkg.MAE_pkg()

Mean Average Error (MAE) metric for point forecasts.

pytorch_forecasting.metrics._point_pkg._mape._mape_pkg.MAPE_pkg()

Mean absolute percentage error metric for point forecasts.

pytorch_forecasting.metrics._point_pkg._mase._mase_pkg.MASE_pkg()

Mean Average scaled Error (MASE) metric for point forecasts.

pytorch_forecasting.metrics._point_pkg._poisson._poisson_loss_pkg.PoissonLoss_pkg()

Poisson loss for count data.

pytorch_forecasting.metrics._point_pkg._rmse._rmse_pkg.RMSE_pkg()

Root mean square error metric for point forecasts.

pytorch_forecasting.metrics._point_pkg._smape._smape_pkg.SMAPE_pkg()

Symmetric mean absolute percentage error metric for point forecasts.

pytorch_forecasting.metrics._point_pkg._tweedie._tweedie_loss_pkg.TweedieLoss_pkg()

Tweedie loss for regression with exponential dispersion models.

pytorch_forecasting.metrics._quantile_pkg._quantile_loss_pkg.QuantileLoss_pkg()

Quantile loss metric for quantile forecasts.

pytorch_forecasting.metrics.base_metrics._base_metrics.DistributionLoss([...])

DistributionLoss base class.

pytorch_forecasting.metrics.base_metrics._base_metrics.Metric([...])

Base metric class that has basic functions that can handle predicting quantiles and operate in log space.

pytorch_forecasting.metrics.base_metrics._base_metrics.MultiHorizonMetric([...])

Abstract class for defining metric for a multihorizon forecast

pytorch_forecasting.metrics.base_metrics._base_metrics.MultiLoss(metrics)

Metric that can be used with multiple metrics.

pytorch_forecasting.metrics.base_metrics._base_metrics.MultivariateDistributionLoss([...])

Base class for multivariate distribution losses.

pytorch_forecasting.metrics.base_metrics._base_metrics.convert_torchmetric_to_pytorch_forecasting_metric(metric)

If necessary, convert a torchmetric to a PyTorch Forecasting metric that works with PyTorch Forecasting models.

pytorch_forecasting.metrics.distributions.BetaDistributionLoss([...])

Beta distribution loss for unit interval data.

pytorch_forecasting.metrics.distributions.ImplicitQuantileNetworkDistributionLoss([...])

Implicit Quantile Network Distribution Loss.

pytorch_forecasting.metrics.distributions.LogNormalDistributionLoss([...])

Log-normal loss.

pytorch_forecasting.metrics.distributions.MQF2DistributionLoss(...)

Multivariate quantile loss based on the article Multivariate Quantile Function Forecaster.

pytorch_forecasting.metrics.distributions.MultivariateNormalDistributionLoss([...])

Multivariate low-rank normal distribution loss.

pytorch_forecasting.metrics.distributions.NegativeBinomialDistributionLoss([...])

Negative binomial loss, e.g. for count data.

pytorch_forecasting.metrics.distributions.NormalDistributionLoss([...])

Normal distribution loss.

pytorch_forecasting.metrics.point.CrossEntropy([...])

Cross entropy loss for classification.

pytorch_forecasting.metrics.point.MAE([...])

Mean average absolute error.

pytorch_forecasting.metrics.point.MAPE([...])

Mean absolute percentage.

pytorch_forecasting.metrics.point.MASE([...])

Mean absolute scaled error

pytorch_forecasting.metrics.point.PoissonLoss([...])

Poisson loss for count data.

pytorch_forecasting.metrics.point.RMSE([...])

Root mean square error.

pytorch_forecasting.metrics.point.SMAPE([...])

Symmetric mean absolute percentage.

pytorch_forecasting.metrics.point.TweedieLoss([...])

Tweedie loss.

pytorch_forecasting.metrics.quantile.QuantileLoss([...])

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