Shortcuts

torcheval.metrics.functional.binary_auroc

torcheval.metrics.functional.binary_auroc(input: Tensor, target: Tensor, *, num_tasks: int = 1, weight: Tensor | None = None, use_fbgemm: bool | None = False) Tensor

Compute AUROC, which is the area under the ROC Curve, for binary classification. Its class version is torcheval.metrics.BinaryAUROC.

Parameters:
  • 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 BinaryAUROC calculation. Default value is 1. BinaryAUROC for each task will be calculated independently.

  • weight (Tensor) – Optional. A manual rescaling weight to match input tensor shape (num_tasks, num_samples) or (n_sample, ).

  • use_fbgemm (bool) – Optional. If set to True, use fbgemm_gpu.metrics.auc (a hand fused kernel). FBGEMM AUC is an approximation of AUC. It does not mask data in case that input values are redundant. For the highly redundant input case, FBGEMM AUC can give a significantly different result.

Examples:

>>> import torch
>>> from torcheval.metrics.functional import binary_auroc
>>> input = torch.tensor([0.1, 0.5, 0.7, 0.8])
>>> target = torch.tensor([1, 0, 1, 1])
>>> binary_auroc(input, target)
tensor(0.6667)

>>> input = torch.tensor([1, 1, 1, 0])
>>> target = torch.tensor([1, 0, 1, 0])
>>> binary_auroc(input, target)
tensor(0.7500)

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

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