简体   繁体   English

R:xgboost曲线roc曲线

[英]R: xgboost plot roc curve

To plot roc curve: 绘制roc曲线:

library(ROCR)
<data cleaning/scrubbing>
<train data>
.....
.....
rf.perf = performance(rf.prediction, "tpr", "fpr") #for RF
logit.perf = performance (logit.prediction, "tpr", "fpr") #for logistic reg
tree.perf = performance(tree.prediction, "tpr", "fpr") #for cart tree
...
plot(re.perf) #a RF roc curve

If I want to run a xgboost classification and subsequently plotting roc: objective = "binary:logistics" 如果我想运行xgboost分类并随后绘制roc:objective =“binary:logistics”

I'm confused with the xgboost's arguments metrics "auc" (page 9 of the CRAN manual ), it says area. 我对xgboost的参数指标“auc”CRAN手册的第9页)感到困惑,它说区域。 How does one plot the curve with tpr and fpr for model comparison? 如何使用tpr和fpr绘制曲线以进行模型比较?

I tried search the net and github, most emphasis on feature importance graph (for xgboost ). 我尝试搜索网络和github,最重视功能重要性图(对于xgboost )。

Thanks 谢谢

Let me first talk about ROC curve 我先来谈谈ROC曲线

The ROC curve is created by plotting the true positive rate (TPR) against the false positive rate (FPR) at various threshold settings. 通过在各种阈值设置下绘制真阳性率(TPR)与假阳性率(FPR)来创建ROC曲线。

In python it can be done easily as: 在python中,它可以很容易地完成:

from sklearn import metrics
def buildROC(target_test,test_preds):
    fpr, tpr, threshold = metrics.roc_curve(target_test, test_preds)
    roc_auc = metrics.auc(fpr, tpr)
    plt.title('Receiver Operating Characteristic')
    plt.plot(fpr, tpr, 'b', label = 'AUC = %0.2f' % roc_auc)
    plt.legend(loc = 'lower right')
    plt.plot([0, 1], [0, 1],'r--')
    plt.ylabel('True Positive Rate')
    plt.xlabel('False Positive Rate')
    plt.gcf().savefig('roc.png')

enter image description here 在此输入图像描述

For example in above image, at certain threshold and at cost of false positive rate 0.2, we can get true positive nearly 0.96 - 0.97 例如,在上面的图像中,在某个阈值和假阳性率0.2的成本,我们可以得到真正的正近0.96 - 0.97

A good documentation on ROC 有关ROC的良好文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM