Shortcuts

torcheval.metrics.functional.binary_binned_precision_recall_curve

torcheval.metrics.functional.binary_binned_precision_recall_curve(input: Tensor, target: Tensor, *, threshold: int | List[float] | Tensor = 100) Tuple[Tensor, Tensor, Tensor]

Compute precision recall curve with given thresholds. Its class version is torcheval.metrics.BinaryBinnedPrecisionRecallCurve.

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

  • target (Tensor) – Tensor of ground truth labels with shape of (n_samples, ).

  • threshold – a integer representing number of bins, a list of thresholds, or a tensor of thresholds.

Returns:

  • precision (Tensor): Tensor of precision result. Its shape is (n_thresholds + 1, )

  • recall (Tensor): Tensor of recall result. Its shape is (n_thresholds + 1, )

  • thresholds (Tensor): Tensor of threshold. Its shape is (n_thresholds, )

Return type:

Tuple

Examples:

>>> import torch
>>> from torcheval.metrics.functional import binary_binned_precision_recall_curve
>>> input = torch.tensor([0.2, 0.8, 0.5, 0.9])
>>> target = torch.tensor([0, 1, 0, 1])
>>> threshold = 5
>>> binary_binned_precision_recall_curve(input, target, threshold)
(tensor([0.5000, 0.6667, 0.6667, 1.0000, 1.0000, 1.0000]),
tensor([1., 1., 1., 1., 0., 0.]),
tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000]))

>>> input = torch.tensor([0.2, 0.3, 0.4, 0.5])
>>> target = torch.tensor([0, 0, 1, 1])
>>> threshold = torch.tensor([0.0000, 0.2500, 0.7500, 1.0000])
>>> binary_binned_precision_recall_curve(input, target, threshold)
(tensor([0.5000, 0.6667, 1.0000, 1.0000, 1.0000]),
tensor([1., 1., 0., 0., 0.]),
tensor([0.0000, 0.2500, 0.7500, 1.0000]))

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