Shortcuts

torcheval.metrics.functional.multilabel_binned_precision_recall_curve

torcheval.metrics.functional.multilabel_binned_precision_recall_curve(input: Tensor, target: Tensor, num_labels: Optional[int] = None, threshold: Union[int, List[float], Tensor] = 100, optimization: str = 'vectorized') Tuple[List[Tensor], List[Tensor], Tensor][source]

Compute precision recall curve with given thresholds. Its class version is torcheval.metrics.MultilabelBinnedPrecisionRecallCurve. See also binary_binned_precision_recall_curve, multiclass_precision_recall_curve

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.
  • threshold – a integer representing number of bins, a list of thresholds, or a tensor of thresholds.
  • optimization (str) – Choose the optimization to use. Accepted values: “vectorized” and “memory”. The “vectorized” optimization makes more use of vectorization but uses more memory; the “memory” optimization uses less memory but takes more steps. Here are the tradeoffs between these two options: - “vectorized”: consumes more memory but is faster on some hardware, e.g. modern GPUs. - “memory”: consumes less memory but can be significantly slower on some hardware, e.g. modern GPUs Generally, on GPUs, the “vectorized” optimization requires more memory but is faster; the “memory” optimization requires less memory but is slower. On CPUs, the “memory” optimization is recommended in all cases; it uses less memory and is faster.
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_binned_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_binned_precision_recall_curve(input, target, num_labels=3, thresholds=5)
(tensor([[0.5000, 0.5000, 1.0000, 1.0000, 0.0000, 1.0000],
         [0.5000, 0.6667, 0.6667, 0.0000, 0.0000, 1.0000],
         [0.7500, 1.0000, 1.0000, 1.0000, 0.0000, 1.0000]]),
 tensor([[1.0000, 0.5000, 0.5000, 0.5000, 0.0000, 0.0000],
         [1.0000, 1.0000, 1.0000, 0.0000, 0.0000, 0.0000],
         [1.0000, 0.6667, 0.3333, 0.3333, 0.0000, 0.0000]]),
 tensor([0.0000, 0.2500, 0.5000, 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