Shortcuts

AUC

Module Interface

class torchmetrics.AUC(reorder=False, **kwargs)[source]

Computes Area Under the Curve (AUC) using the trapezoidal rule

Forward accepts two input tensors that should be 1D and have the same number of elements

Parameters
  • reorder (bool) – AUC expects its first input to be sorted. If this is not the case, setting this argument to True will use a stable sorting algorithm to sort the input in descending order

  • kwargs (Any) – Additional keyword arguments, see Advanced metric settings for more info.

Initializes internal Module state, shared by both nn.Module and ScriptModule.

compute()[source]

Computes AUC based on inputs passed in to update previously.

Return type

Tensor

update(preds, target)[source]

Update state with predictions and targets.

Parameters
  • preds (Tensor) – Predictions from model (probabilities, or labels)

  • target (Tensor) – Ground truth labels

Return type

None

Functional Interface

torchmetrics.functional.auc(x, y, reorder=False)[source]

Computes Area Under the Curve (AUC) using the trapezoidal rule.

Parameters
  • x (Tensor) – x-coordinates, must be either increasing or decreasing

  • y (Tensor) – y-coordinates

  • reorder (bool) – if True, will reorder the arrays to make it either increasing or decreasing

Return type

Tensor

Returns

Tensor containing AUC score

Raises
  • ValueError – If both x and y tensors are not 1d.

  • ValueError – If both x and y don’t have the same numnber of elements.

  • ValueError – If x tesnsor is neither increasing nor decreasing.

Example

>>> from torchmetrics.functional import auc
>>> x = torch.tensor([0, 1, 2, 3])
>>> y = torch.tensor([0, 1, 2, 2])
>>> auc(x, y)
tensor(4.)
>>> auc(x, y, reorder=True)
tensor(4.)