mindspore.train.auc
- mindspore.train.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 (bool) – If False, x must rise or fall monotonously. If True, x will be sorted in ascending order. Default: False.
- Returns
float, the area under the ROC-curve.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore.train import ROC, auc >>> >>> 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 = ROC(pos_label=2) >>> metric.clear() >>> metric.update(y_pred, y) >>> fpr, tpr, thre = metric.eval() >>> output = auc(fpr, tpr) >>> print(output) 0.5357142857142857