绘制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 =“二元:物流”
我对xgboost的参数指标“auc”(CRAN manual的第9页)感到困惑,它说区域.
如何使用tpr和fpr绘制曲线以进行模型比较?
我尝试搜索网络和github,最重视功能重要性图(对于xgboost).
谢谢
最佳答案 我先来谈谈ROC曲线
The ROC curve is created by plotting the true positive rate (TPR) against the false positive rate (FPR) at various threshold settings.
在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