2015-11-04 126 views
4

要繪製ROC曲線:R:xgboost情節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: 目標= 「二進制:物流」

我很困惑與xgboost的參數指標「auc」(頁碼9的CRAN manual),它表示區域。 如何用tpr和fpr繪製曲線進行模型比較?

我試過搜索網和github,最重視功能重要性圖(對於xgboost)。

感謝

+1

只是爲了澄清,該AUC是面積UND呃接收者操作符曲線(ROC)的曲線。這是0-1之間的度量。對我而言,你所問的問題並不完全清楚。我猜你只是想繪製中華民國,但這樣做有困難?也許包括一個[可重現的例子](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example),這可能有所幫助。 – BlankUsername

回答

0

讓我先說說ROC曲線

ROC曲線是通過繪製反對各種閾值設置的假陽性率(FPR)真陽性率(TPR)創建的。

在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