torcheval.metrics.functional.auc¶
-
torcheval.metrics.functional.
auc
(x: Tensor, y: Tensor, reorder: bool = False) Tensor [source]¶ Computes Area Under the Curve (AUC) using the trapezoidal rule. :param x: x-coordinates :param y: y-coordinates :param reorder: sorts the x input tensor in order, default value is False
Returns: Tensor containing AUC score (float) Raises: ValueError – If both x
andy
don’t have the same shape. If bothx
andy
have atleast 1 element.Example
>>> from torcheval.metrics.functional.aggregation.auc import auc >>> x = torch.tensor([0,.1,.2,.3]) >>> y = torch.tensor([1,1,1,1]) >>> auc(x, y) tensor([0.3000]) >>> y = torch.tensor([[0, 4, 0, 4, 3], [1, 1, 2, 1, 1], [4, 3, 1, 4, 4], [1, 0, 0, 3, 0]]) >>> x = torch.tensor([[0.2535, 0.1138, 0.1324, 0.1887, 0.3117], [0.1434, 0.4404, 0.1100, 0.1178, 0.1883], [0.2344, 0.1743, 0.3110, 0.0393, 0.2410], [0.1381, 0.1564, 0.0320, 0.2220, 0.4515]]) >>> auc(x, y, reorder=True) # Reorders X and calculates AUC. tensor([0.3667, 0.3343, 0.8843, 0.5048])