Shortcuts

torcheval.metrics.functional.multiclass_auprc

torcheval.metrics.functional.multiclass_auprc(input: Tensor, target: Tensor, num_classes: Optional[int] = None, *, average: Optional[str] = 'macro') Tensor[source]

Compute AUPRC, also called Average Precision, which is the area under the Precision-Recall Curve, for multiclass classification. Its class version is torcheval.metrics.MulticlassAUPRC.

Precision is defined as \(\frac{T_p}{T_p+F_p}\); it is the probability that a positive prediction from the model is a true positive. Recall is defined as \(\frac{T_p}{T_p+F_n}\); it is the probability that a true positive is predicted to be positive by the model.

The precision-recall curve plots the recall on the x axis and the precision on the y axis, both of which are bounded between 0 and 1. This function returns the area under that graph. If the area is near one, the model supports a threshold which correctly identifies a high percentage of true positives while also rejecting enough false examples so that most of the true predictions are true positives.

In the multiclass version of auprc, the target tensor is 1-dimensional and contains an integer entry representing the class for each example in the input tensor. Each class is considered independently in a one-vs-all fashion, examples for that class are labeled condition true and all other classes are considered condition false.

The results of N class multiclass auprc without an average is equivalent to binary auprc with N tasks if:

  1. the input is transposed, in binary classification examples are associated with columns, whereas they are associated with rows in multiclass classification.
  2. the target is translated from the form [1,0,1] to the form [[0,1,0], [1,0,1]]

See also binary_auprc, multilabel_auprc

Parameters:
  • input (Tensor) – 2 dimensional tensor of label predictions It should be probabilities or logits with shape of (n_sample, n_class).
  • target (Tensor) – 1 dimensional tensor of ground truth labels with shape of (n_samples, ).
  • num_classes (int) – Number of classes.
  • average (str, optional) –
    • 'macro' [default]:
      Calculate metrics for each class separately, and return their unweighted mean.
    • None or 'none':
      Calculate the metric for each class separately, and return the metric for every class.
Examples::
>>> import torch
>>> from torcheval.metrics.functional import multiclass_auprc
>>> input = tensor([[0.5647, 0.2726],
                    [0.9143, 0.1895],
                    [0.7782, 0.3082]])
>>> target = tensor([0, 1, 0])
>>> multiclass_auprc(input, target, average=None)
tensor([0.5833, 0.3333])
>>> multiclass_auprc(input, target)
tensor(0.4583)
>>> input = torch.tensor([[0.1, 1],
                          [0.5, 1],
                          [0.7, 1],
                          [0.8, 0]])
>>> target = torch.tensor([1, 0, 0, 1])
>>> multiclass_auprc(input, target, 2, average=None)
tensor([0.5833, 0.4167])

Connection with binary >>> from torcheval.metrics.functional import binary_auprc >>> input = torch.tensor([[0.1, 0.5, 0.7, 0.8], >>> [1, 1, 1, 0]]) >>> target = torch.tensor([[0, 1, 1, 0], >>> [1, 0, 0, 1]]) >>> binary_auprc(input, target, num_tasks=2) tensor([0.5833, 0.4167])

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