首页 文章

R:xgboost曲线roc曲线

提问于
浏览
4

绘制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

如果我想运行 xgboost 分类并随后绘制roc:objective = "binary:logistics"

我'm confused with the xgboost' s参数指标"auc"(CRAN manual的第9页),它表示区域 . 如何使用tpr和fpr绘制曲线以进行模型比较?

我尝试搜索网络和github,最重视功能重要性图(适用于 xgboost ) .

谢谢

1 回答

  • 1

    我先来谈谈ROC曲线

    通过在各种阈值设置下绘制真阳性率(TPR)与假阳性率(FPR)来创建ROC曲线 .

    在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

    例如,在上面的图像中,在某个阈值和假阳性率0.2的成本,我们可以得到真正的正近0.96 - 0.97

    A good documentation on ROC

相关问题