Shortcuts

torcheval.metrics.functional.multiclass_precision_recall_curve

torcheval.metrics.functional.multiclass_precision_recall_curve(input: Tensor, target: Tensor, *, num_classes: Optional[int] = None) Tuple[List[Tensor], List[Tensor], List[Tensor]][source]

Returns precision-recall pairs and their corresponding thresholds for multi-class classification tasks. If a class is missing from the target tensor, its recall values are set to 1.0.

Its class version is torcheval.metrics.MulticlassPrecisionRecallCurve. See also binary_precision_recall_curve, multilabel_precision_recall_curve

Parameters:
  • input (Tensor) – Tensor of label predictions It should be probabilities or logits with shape of (n_sample, n_class).
  • target (Tensor) – Tensor of ground truth labels with shape of (n_samples, ).
  • num_classes (Optional) – Number of classes. Set to the second dimension of the input if num_classes is None.
Returns:

List[torch.Tensor], recall: List[torch.Tensor], thresholds: List[torch.Tensor])

precision: List of precision result. Each index indicates the result of a class. recall: List of recall result. Each index indicates the result of a class. thresholds: List of threshold. Each index indicates the result of a class.

Return type:

a tuple of (precision

Examples:

>>> import torch
>>> from torcheval.metrics.functional import multiclass_precision_recall_curve
>>> input = torch.tensor([[0.1, 0.1, 0.1, 0.1], [0.5, 0.5, 0.5, 0.5], [0.7, 0.7, 0.7, 0.7], [0.8, 0.8, 0.8, 0.8]])
>>> target = torch.tensor([0, 1, 2, 3])
>>> multiclass_precision_recall_curve(input, target, num_classes=4)
([tensor([0.2500, 0.0000, 0.0000, 0.0000, 1.0000]),
tensor([0.2500, 0.3333, 0.0000, 0.0000, 1.0000]),
tensor([0.2500, 0.3333, 0.5000, 0.0000, 1.0000]),
tensor([0.2500, 0.3333, 0.5000, 1.0000, 1.0000])],
[tensor([1., 0., 0., 0., 0.]),
tensor([1., 1., 0., 0., 0.]),
tensor([1., 1., 1., 0., 0.]),
tensor([1., 1., 1., 1., 0.])],
[tensor([0.1000, 0.5000, 0.7000, 0.8000]),
tensor([0.1000, 0.5000, 0.7000, 0.8000]),
tensor([0.1000, 0.5000, 0.7000, 0.8000]),
tensor([0.1000, 0.5000, 0.7000, 0.8000])])

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources