官方地址:点击打开链接

形式:sklearn.metrics.auc(x, y, reorder=False)

规则:利用梯形法则计算曲线下的面积(AUC)。

Parameters:

x : array, shape = [n]

x 坐标

y : array, shape = [n]

y 坐标

reorder : boolean, optional (default=False)

如果是True,假设在关系的情况下曲线是上升的,就像ROC曲线一样。如果曲线不上升,结果将是错误的。

Returns:

auc : float



已经得到了FPR.TPR,由此就得到了横纵坐标,然后用高数中学习的计算曲面面积的方法,也就梯度法(一种积分方法来计算曲线下面积)

import numpy as np
from sklearn import metrics
y = np.array([1, 1, 2, 2])
scores = np.array([0.1, 0.4, 0.35, 0.8])
fpr, tpr, thresholds = metrics.roc_curve(y, scores, pos_label=2)
print(fpr,'\n',tpr,'\n',thresholds)


sklearn.metrics.auc解析_sklearn.metrics.auc



这个比较简单,绘图如下:

sklearn.metrics.auc解析_数据_02

就是计算黄色部分的面积,口算都可得到AUC=0.75

但是复杂的数据还是要用标准的算法,详细过程可以参考博客,写的很好:点击打开链接

只想知道怎么使用,不用知道原理的,计算代码如下:

import numpy as np
from sklearn import metrics
y = np.array([1, 1, 2, 2])
scores = np.array([0.1, 0.4, 0.35, 0.8])
fpr, tpr, thresholds = metrics.roc_curve(y, scores, pos_label=2)
print(fpr,'\n',tpr,'\n',thresholds)
print(metrics.auc(fpr,tpr))


sklearn.metrics.auc解析_auc_03