ROC和AUC定义
ROC全称是“受试者工作特征”(Receiver Operating Characteristic)。ROC曲线的面积就是AUC(Area Under the Curve)。AUC用于衡量“二分类问题”机器学习算法性能(泛化能力)
计算ROC的关键概念
- P(Positive):预测值为正例
- N(Negative):预测值为反例
- T(True):预测值与真实值相同
- F(False):预测值与真实值相反
- TP:被模型预测为正类的正样本
- TN:被模型预测为负类的负样本
- FP:被模型预测为正类的负样本
- FN:被模型预测为负类的正样本


from sklearn.metrics import roc_curve
from sklearn.metrics import auc
# fpr, tpr
fpr, tpr, thresholds = roc_curve(train_y, oof_lgb,pos_label=1)
# 计算auc
auc = auc(fpr, tpr)
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.plot(fpr, tpr, label='LightGBM (AUC = {:.3f})'.format(auc))
plt.plot([0, 1], [0, 1], 'k--')
plt.xlabel('False positive rate')
plt.ylabel('True positive rate')
plt.title('ROC curve ')
plt.legend(loc='best')
plt.show()
参考:
https://blog.csdn.net/dongjinkun/article/details/109899733
https://blog.csdn.net/weixin_45592298/article/details/115307705
版权声明:本文为A496608119原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。