Shortcuts

torcheval.metrics.functional.multiclass_binned_precision_recall_curve

torcheval.metrics.functional.multiclass_binned_precision_recall_curve(input: Tensor, target: Tensor, num_classes: 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.MulticlassBinnedPrecisionRecallCurve. See also binary_binned_precision_recall_curve

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 (Tensor) – 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: 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]))

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