Shortcuts

torcheval.metrics.AUC

class torcheval.metrics.AUC(*, reorder: bool = True, n_tasks: int = 1, device: device | None = None)

Computes Area Under the Curve (AUC) using the trapezoidal rule. Supports x and y being two dimensional tensors, each row is treated as its own list of x and y coordinates returning one dimensional tensor should be returned with the AUC for each row calculated.

Args: reorder (bool): Reorder the input tensor for auc computation. Default value is True. num_tasks (int): Number of tasks that need AUC calculation. Default value is 1.

>>> from torcheval.metrics.aggregation.auc import AUC
>>> metric = AUC()
>>> metric.update(torch.tensor([0,.2,.3,.1]), torch.tensor([1,1,1,1]))
>>> metric.compute()
tensor([0.3000])
>>> metric.reset()
>>> metric.update(torch.tensor([0,.1,.13,.2]), torch.tensor([1,1,2,4]))
>>> metric.update(torch.tensor([1.,2.,.1, 3.]), torch.tensor([1,2,3,2]))
>>> metric.compute()
tensor([5.8850])
>>> metric = AUC(n_tasks=2) # n_tasks should be equal to first dimension of x, y in update()
>>> x = torch.tensor([[0.3941, 0.2980, 0.3080],
                      [0.1448, 0.6090, 0.2462]])
>>> y = torch.tensor([[1, 0, 4],
                      [0, 4, 2]])
>>> metric.update(x, y)
>>> x1 = torch.tensor([[0.4562, 0.1200, 0.4238],
                       [0.4076, 0.4448, 0.1476]])
>>> y1 = torch.tensor([[3, 4, 3],
                       [2, 0, 4]])
>>> metric.update(x1, y1)
>>> metric.compute()
tensor([0.7479, 0.9898])
__init__(*, reorder: bool = True, n_tasks: int = 1, device: device | None = None) None

Initialize a metric object and its internal states.

Use self._add_state() to initialize state variables of your metric class. The state variables should be either torch.Tensor, a list of torch.Tensor, a dictionary with torch.Tensor as values, or a deque of torch.Tensor.

Methods

__init__(*[, reorder, n_tasks, device])

Initialize a metric object and its internal states.

compute()

Computes AUC based on inputs passed in to update previously.

load_state_dict(state_dict[, strict])

Loads metric state variables from state_dict.

merge_state(metrics)

Implement this method to update the current metric's state variables to be the merged states of the current metric and input metrics.

reset()

Reset the metric state variables to their default value.

state_dict()

Save metric state variables in state_dict.

to(device, *args, **kwargs)

Move tensors in metric state variables to device.

update(x, y)

Updates and returns variables required to compute area under the curve.

Attributes

device

The last input device of Metric.to().

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