roc_auc_score()计算二分类的AUC

二分类直接用预测值和标签值计算:
label:样本的真实标签
score:模型的打分结果中类别为1的概率,是一个n行 ,1列的数组

from sklearn import metrics
import matplotlib.pyplot as plt
import numpy as np
from sklearn.metrics import roc_auc_score
label = np.array([0, 0, 1, 1])
predict =np.array([[0.3,0.7],[0.6,0.4],[0.1,0.9],[0.8,0.2]])
score=predict[:,1]# 取预测标签为1的概率
print(score)
fpr,tpr,thresholds=metrics.roc_curve(label,score)
print('FPR:',fpr)
print('TPR:',tpr)
print('thresholds:',thresholds)

plt.plot(fpr,tpr)
plt.show()
auc=roc_auc_score(label, score)
print(auc)

你可能感兴趣的:(sklearn,python)