CoverageRate#

class torch_uncertainty.metrics.classification.CoverageRate(num_classes=None, average='micro', validate_args=True, **kwargs)[source]#

Empirical coverage rate metric.

Parameters:
  • num_classes (int | None, optional) – Number of classes. Defaults to None.

  • average (str, optional) –

    Defines the reduction that is applied over labels. Should be one of the following:

    • 'macro' (default): Compute the metric for each class separately and find their unweighted mean. This does not take label imbalance into account.

    • 'micro': Sum statistics across over all labels.

  • validate_args (bool, optional) – Whether to validate the arguments. Defaults to True.

  • kwargs – Additional keyword arguments, see Advanced metric settings.

Raises:
  • ValueError – If num_classes is None and average is not micro.

  • ValueError – If num_classes is not an integer larger than 1.

  • ValueError – If average is not one of macro or micro.

compute()[source]#

Compute the coverage rate.

Returns:

The coverage rate.

Return type:

Tensor

update(preds, target)[source]#

Update the metric state with predictions and targets.

Parameters:
  • preds (torch.Tensor) – predicted sets tensor of shape (B, C), where B is the batch size and C is the number of classes.

  • target (torch.Tensor) – target sets tensor of shape (B,).