torcheval.metrics.functional.multilabel_precision_recall_curve¶
- torcheval.metrics.functional.multilabel_precision_recall_curve(input: Tensor, target: Tensor, *, num_labels: int | None = None) Tuple[List[Tensor], List[Tensor], List[Tensor]] ¶
Returns precision-recall pairs and their corresponding thresholds for multi-label classification tasks. If there are no samples for a label in the target tensor, its recall values are set to 1.0.
Its class version is
torcheval.metrics.MultilabelPrecisionRecallCurve
.- Parameters:
input (Tensor) – Tensor of label predictions It should be probabilities or logits with shape of (n_sample, n_label).
target (Tensor) – Tensor of ground truth labels with shape of (n_samples, n_label).
num_labels (Optional) – Number of labels.
- Returns:
- List[torch.Tensor], recall: List[torch.Tensor], thresholds: List[torch.Tensor])
precision: List of precision result. Each index indicates the result of a label. recall: List of recall result. Each index indicates the result of a label. thresholds: List of threshold. Each index indicates the result of a label.
- Return type:
a tuple of (precision
Examples:
>>> import torch >>> from torcheval.metrics.functional import multilabel_precision_recall_curve >>> input = torch.tensor([[0.75, 0.05, 0.35], [0.45, 0.75, 0.05], [0.05, 0.55, 0.75], [0.05, 0.65, 0.05]]) >>> target = torch.tensor([[1, 0, 1], [0, 0, 0], [0, 1, 1], [1, 1, 1]]) >>> multilabel_precision_recall_curve(input, target, num_labels=3) ([tensor([0.5, 0.5, 1.0, 1.0]), tensor([0.5, 0.66666667, 0.5, 0.0, 1.0]), tensor([0.75, 1.0, 1.0, 1.0])], [tensor([1.0, 0.5, 0.5, 0.0]), tensor([1.0, 1.0, 0.5, 0.0, 0.0]), tensor([1.0, 0.66666667, 0.33333333, 0.0])], [tensor([0.05, 0.45, 0.75]), tensor([0.05, 0.55, 0.65, 0.75]), tensor([0.05, 0.35, 0.75])])