mindspore.nn.auc

mindspore.nn.auc(x, y, reorder=False)[源代码]

使用梯形法则计算曲线下面积AUC(Area Under the Curve,AUC)。这是一个一般函数,给定曲线上的点, 用于计算ROC (Receiver Operating Curve, ROC) 曲线下的面积。

参数:

  • x (Union[np.array, list]) - 从ROC曲线(False Positive Rate, FPR)来看,np.array具有假阳性率。如果是多类,则为np.array列表。Shape为 \((N)\)

  • y (Union[np.array, list]) - 从ROC曲线(True Positive Rate, TPR)来看,np.array具有假阳性率。如果是多类,则为np.array列表。Shape为 \((N)\)

  • reorder (bool) - 如果为False,那么 x 必须是单调上升或下降的,如果为True,那么 x 将会按照升序排序。默认值:False。

返回:

float,曲线下面积的值AUC。

支持平台:

Ascend GPU CPU

样例:

>>> 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