Auc¶
注意:目前只用Python实现Auc,可能速度略慢
该接口计算Auc,在二分类(binary classification)中广泛使用。相关定义参考 https://en.wikipedia.org/wiki/Receiver_operating_characteristic#Area_under_the_curve 。
该接口创建四个局部变量true_positives, true_negatives, false_positives和false_negatives,用于计算Auc。为了离散化AUC曲线,使用临界值的线性间隔来计算召回率和准确率的值。用false positive的召回值高度计算ROC曲线面积,用recall的准确值高度计算PR曲线面积。
参数¶
name (str,可选) - 具体用法请参见 Name,一般无需设置,默认值为 None。
curve (str) - 将要计算的曲线名的详情,曲线包括ROC(默认)或者PR(Precision-Recall-curve)。
返回¶
初始化后的 Auc
对象
返回类型¶
Auc
代码示例¶
import paddle.fluid as fluid
import numpy as np
# init the auc metric
auc_metric = fluid.metrics.Auc("ROC")
# suppose that batch_size is 128
batch_num = 100
batch_size = 128
for batch_id in range(batch_num):
class0_preds = np.random.random(size = (batch_size, 1))
class1_preds = 1 - class0_preds
preds = np.concatenate((class0_preds, class1_preds), axis=1)
labels = np.random.randint(2, size = (batch_size, 1))
auc_metric.update(preds = preds, labels = labels)
# shall be some score closing to 0.5 as the preds are randomly assigned
print("auc for iteration %d is %.2f" % (batch_id, auc_metric.eval()))