torcheval.metrics.functional.binary_binned_auprc¶
-
torcheval.metrics.functional.
binary_binned_auprc
(input: Tensor, target: Tensor, *, num_tasks: int = 1, threshold: Union[int, List[float], Tensor] = 100) Tuple[Tensor, Tensor] [source]¶ Binned Version of AUPRC, which is the area under the AUPRC Curve, for binary classification. Its class version is
torcheval.metrics.BinaryBinnedAUPRC
.Computation is done by computing the area under the precision/recall curve; precision and recall are computed for the buckets defined by threshold.
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 binary_binned_auprc calculation. Default value is 1. binary_binned_auprc for each task will be calculated independently.
- threshold (Tensor, int, List[float]) – Either an integer representing the number of bins, a list of thresholds, or a tensor of thresholds. The same thresholds will be used for all tasks. If threshold is a tensor, it must be 1D. If list or tensor is given, the first element must be 0 and the last must be 1.
Examples
>>> import torch >>> from torcheval.metrics.functional import binary_binned_auprc >>> input = torch.tensor([0.2, 0.3, 0.4, 0.5]) >>> target = torch.tensor([0, 0, 1, 1]) >>> binary_binned_auprc(input, target, threshold=5) (tensor(1.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_auprc(input, target, threshold=threshold) (tensor(0.6667), tensor([0.0000, 0.2500, 0.7500, 1.0000]))
>>> input = torch.tensor([[0.2, 0.3, 0.4, 0.5], [0, 1, 2, 3]]) >>> target = torch.tensor([[0, 0, 1, 1], [0, 1, 1, 1]]) >>> threshold = torch.tensor([0.0000, 0.2500, 0.7500, 1.0000]) >>> binary_binned_auprc(input, target, num_tasks=2, threshold=threshold) (tensor([0.6667, 1.0000], tensor([0.0000, 0.2500, 0.7500, 1.0000]))