multiclasslogauc
Metric
MulticlassLogAUCfromtorchmetrics(torchmetrics.classification.MulticlassLogAUC)
When to invoke this skill
The user has predictions + ground truth and asks to evaluate with MulticlassLogAUC, or
mentions torchmetrics.classification.MulticlassLogAUC directly, or wants the standard torchmetrics implementation.
Reference signature
from torchmetrics.classification import MulticlassLogAUC
# MulticlassLogAUC(num_classes: int, fpr_range: Tuple[float, float] = (0.001, 0.1), average: Optional[Literal['macro', 'none']] = None, thresholds: Union[int, List[float], torch.Tensor, NoneType] = None, ignore_index: Optional[int] = None, validate_args: bool = True, **kwargs: Any) -> None
Library docstring
Compute the `Log AUC`_ score for multiclass classification tasks.
The score is computed by first computing the ROC curve, which then is interpolated to the specified range of false
positive rates (FPR) and then the log is taken of the FPR before the area under the curve (AUC) is computed. The
score is commonly used in applications where the positive and negative are imbalanced and a low false positive rate
is of high importance.
As input to ``forward`` and ``update`` the metric accepts the following input:
- ``preds`` (:class:`~torch.Tensor`): A float tensor of shape ``(N, C, ...)`` containing probabilities or logits
for each observation. If preds has values outside [0,1] range we consider the input to be logits and will auto
apply softmax per sample.
- ``target`` (:class:`~torch.Tensor`): An int tensor of shape ``(N, ...)`` containing ground truth labels, and
therefore only contain values in the [0, n_classes-1] range (except if `ignore_index` is specified).
As output to ``forward`` and ``compute`` the metric returns the following output:
- ``logauc`` (:class:`~torch.Tensor`): If `average=None|"none"` then a 1d tensor of shape (n_classes, ) will
be returned with logauc score per class. If `average="macro"` then a single scalar is returned.
Additional dimension ``...`` will be flattened into the batch dimension.
The implementation both supports calculating the metric in a non-binned but accurate version and a binned version
that is less accurate but more memory efficient. Setting the `thresholds` argument to `None` will activate the
non-binned version that uses memory of size :math:`\mathcal{O}(n_{samples})` whereas setting the `thresholds`
argument to either an integer, list or a 1d tensor will use a binned version that uses memory of
size :math:`\mathcal{O}(n_{thresholds})` (constant memory).
Args:
num_classes: Integer specifying the number of classes
fpr_range: 2-element tuple with the lower and upper bound of the false positive rate range to compute the log
AUC score.
average:
Defines the reduction that is applied over classes. Should be one of the following:
- ``"macro"``: Calculate score for each class
Quick recipe
import torchmetrics.classification as _m
score = _m.MulticlassLogAUC(y_true, y_pred)
Don'ts
- Don't reimplement when the library version handles edge cases (NaN, ties, empty inputs) better than a hand-rolled formula.
- Always check the library version's argument order — sklearn is
(y_true, y_pred)while torchmetrics is(preds, target).