Shortcuts

Coverage Error

Module Interface

class torchmetrics.CoverageError(**kwargs)[source]

Computes multilabel coverage error [1]. The score measure how far we need to go through the ranked scores to cover all true labels. The best value is equal to the average number of labels in the target tensor per sample.

Parameters

kwargs (Any) – Additional keyword arguments, see Advanced metric settings for more info.

Example

>>> from torchmetrics import CoverageError
>>> _ = torch.manual_seed(42)
>>> preds = torch.rand(10, 5)
>>> target = torch.randint(2, (10, 5))
>>> metric = CoverageError()
>>> metric(preds, target)
tensor(3.9000)

References

[1] Tsoumakas, G., Katakis, I., & Vlahavas, I. (2010). Mining multi-label data. In Data mining and knowledge discovery handbook (pp. 667-685). Springer US.

Initializes internal Module state, shared by both nn.Module and ScriptModule.

compute()[source]

Computes the multilabel coverage error.

Return type

Tensor

update(preds, target, sample_weight=None)[source]
Parameters
  • preds (Tensor) – tensor of shape [N,L] where N is the number of samples and L is the number of labels. Should either be probabilities of the positive class or corresponding logits

  • target (Tensor) – tensor of shape [N,L] where N is the number of samples and L is the number of labels. Should only contain binary labels.

  • sample_weight (Optional[Tensor]) – tensor of shape N where N is the number of samples. How much each sample should be weighted in the final score.

Return type

None

Functional Interface

torchmetrics.functional.coverage_error(preds, target, sample_weight=None)[source]

Computes multilabel coverage error [1]. The score measure how far we need to go through the ranked scores to cover all true labels. The best value is equal to the average number of labels in the target tensor per sample.

Parameters
  • preds (Tensor) – tensor of shape [N,L] where N is the number of samples and L is the number of labels. Should either be probabilities of the positive class or corresponding logits

  • target (Tensor) – tensor of shape [N,L] where N is the number of samples and L is the number of labels. Should only contain binary labels.

  • sample_weight (Optional[Tensor]) – tensor of shape N where N is the number of samples. How much each sample should be weighted in the final score.

Example

>>> from torchmetrics.functional import coverage_error
>>> _ = torch.manual_seed(42)
>>> preds = torch.rand(10, 5)
>>> target = torch.randint(2, (10, 5))
>>> coverage_error(preds, target)
tensor(3.9000)

References

[1] Tsoumakas, G., Katakis, I., & Vlahavas, I. (2010). Mining multi-label data. In Data mining and knowledge discovery handbook (pp. 667-685). Springer US.

Return type

Tensor