mindspore.nn.auc
- mindspore.nn.auc(x, y, reorder=False)[source]
Computes the AUC(Area Under the Curve) using the trapezoidal rule. This is a general function, given points on a curve. For computing the area under the ROC-curve.
- Parameters
x (Union[np.array, list]) – From the ROC curve(fpr), np.array with false positive rates. If multiclass, this is a list of such np.array, one for each class. The shape \((N)\).
y (Union[np.array, list]) – From the ROC curve(tpr), np.array with true positive rates. If multiclass, this is a list of such np.array, one for each class. The shape \((N)\).
reorder (boolean) – If True, assume that the curve is ascending in the case of ties, as for an ROC curve. If the curve is non-ascending, the result will be wrong. Default: False.
- Returns
Compute result.
- Return type
Scalar (float)
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import nn >>> >>> y_pred = np.array([[3, 0, 1], [1, 3, 0], [1, 0, 2]]) >>> y = np.array([[0, 2, 1], [1, 2, 1], [0, 0, 1]]) >>> metric = nn.ROC(pos_label=2) >>> metric.clear() >>> metric.update(y_pred, y) >>> fpr, tpr, thre = metric.eval() >>> output = nn.auc(fpr, tpr) >>> print(output) 0.5357142857142857