torcheval.metrics.functional.binary_auprc(input: Tensor, target: Tensor, *, num_tasks: int = 1) Tensor

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

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.

  • input (Tensor) – Tensor of label predictions It should be predicted label, probabilities or logits with shape of (num_tasks, n_sample) or (n_sample, ).

  • target (Tensor) – Tensor of ground truth labels with shape of (num_tasks, n_sample) or (n_sample, ).

  • num_tasks (int) – Number of tasks that need BinaryAUPRC calculation. Default value is 1. Binary AUPRC for each task will be calculated independently. Results are equivelent to calling binary_auprc for each row.


>>> import torch
>>> from torcheval.metrics.functional import binary_auprc
>>> input = torch.tensor([0.1, 0.5, 0.7, 0.8])
>>> target = torch.tensor([1, 0, 1, 1])
>>> binary_auprc(input, target)
tensor(0.9167) # scalar returned with 1D input tensors

>>> input = torch.tensor([[1, 1, 1, 0]])
>>> target = torch.tensor([[1, 0, 1, 0]])
>>> binary_auprc(input, target)
tensor([0.6667]) # 1D tensor returned with 2D input tensors

>>> input = torch.tensor([[0.1, 0.5, 0.7, 0.8],
>>>                       [1, 1, 1, 0]])
>>> target = torch.tensor([[1, 0, 1, 1],
>>>                        [1, 0, 1, 0]])
>>> binary_auprc(input, target, num_tasks=2)
tensor([0.9167, 0.6667])


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources