torcheval.metrics.functional.multiclass_binned_precision_recall_curve¶
- torcheval.metrics.functional.multiclass_binned_precision_recall_curve(input: Tensor, target: Tensor, num_classes: int | None = None, threshold: int | List[float] | Tensor = 100) Tuple[List[Tensor], List[Tensor], Tensor] ¶
Compute precision recall curve with given thresholds. Its class version is
torcheval.metrics.MulticlassBinnedPrecisionRecallCurve
.- Parameters:
input (Tensor) – Tensor of label predictions It should be probabilities or logits with shape of (n_sample, n_class).
target (Tensor) – Tensor of ground truth labels with shape of (n_samples, ).
num_classes (Optional) – Number of classes. Set to the second dimension of the input if num_classes is None.
threshold – a integer representing number of bins, a list of thresholds, or a tensor of thresholds.
- Returns:
- List[torch.Tensor], recall: List[torch.Tensor], thresholds: torch.Tensor)
precision: List of precision result. Each index indicates the result of a class. recall: List of recall result. Each index indicates the result of a class. thresholds: Tensor of threshold. The threshold is used for all classes.
- Return type:
a tuple of (precision
Examples:
>>> import torch >>> from torcheval.metrics.functional import multiclass_binned_precision_recall_curve >>> input = torch.tensor([[0.1, 0.1, 0.1, 0.1], [0.5, 0.5, 0.5, 0.5], [0.7, 0.7, 0.7, 0.7], [0.8, 0.8, 0.8, 0.8]]) >>> target = torch.tensor([0, 1, 2, 3]) >>> multiclass_binned_precision_recall_curve(input, target, num_classes=4, threshold=5) ([tensor([0.2500, 0.0000, 0.0000, 0.0000, 1.0000, 1.0000]), tensor([0.2500, 0.3333, 0.3333, 0.0000, 1.0000, 1.0000]), tensor([0.2500, 0.3333, 0.3333, 0.0000, 1.0000, 1.0000]), tensor([0.2500, 0.3333, 0.3333, 1.0000, 1.0000, 1.0000])], [tensor([1., 0., 0., 0., 0., 0.]), tensor([1., 1., 1., 0., 0., 0.]), tensor([1., 1., 1., 0., 0., 0.]), tensor([1., 1., 1., 1., 0., 0.])], tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000])) >>> input = torch.tensor([[0.1, 0.1, 0.1, 0.1], [0.5, 0.5, 0.5, 0.5], [0.7, 0.7, 0.7, 0.7], [0.8, 0.8, 0.8, 0.8]]) >>> target = torch.tensor([0, 1, 2, 3]) >>> threshold = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] >>> multiclass_binned_precision_recall_curve(input, target, num_classes=4, threshold=threshold) ([tensor([0.2500, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 1.0000]), tensor([0.2500, 0.3333, 0.3333, 0.3333, 0.3333, 0.0000, 0.0000, 0.0000, 1.0000, 1.0000]), tensor([0.2500, 0.3333, 0.3333, 0.3333, 0.3333, 0.5000, 0.5000, 0.0000, 1.0000, 1.0000]), tensor([0.2500, 0.3333, 0.3333, 0.3333, 0.3333, 0.5000, 0.5000, 1.0000, 1.0000, 1.0000])], [tensor([1., 0., 0., 0., 0., 0., 0., 0., 0., 0.]), tensor([1., 1., 1., 1., 1., 0., 0., 0., 0., 0.]), tensor([1., 1., 1., 1., 1., 1., 1., 0., 0., 0.]), tensor([1., 1., 1., 1., 1., 1., 1., 1., 0., 0.])], tensor([0.1000, 0.2000, 0.3000, 0.4000, 0.5000, 0.6000, 0.7000, 0.8000, 0.9000]))