Plotting a ROC curve from a random forest classification

自作多情 提交于 2019-12-23 21:40:03

问题


I'm trying to plot ROC curve of a random forest classification. Plotting works, but I think I'm plotting the wrong data since the resulting plot only has one point (the accuracy).

This is the code I use:

set.seed(55)
data.controls <- cforest_unbiased(ntree=100, mtry=3)
data.rf <- cforest(type ~ ., data = dataset ,controls=data.controls) 
pred <- predict(data.rf, type="response")
preds <- prediction(as.numeric(pred), dataset$type)
    perf <- performance(preds,"tpr","fpr")
    performance(preds,"auc")@y.values
    confusionMatrix(pred, dataset$type)

plot(perf,col='red',lwd=3)
abline(a=0,b=1,lwd=2,lty=2,col="gray")

回答1:


To plot a receiver operating curve you need to hand over continuous output of the classifier, e.g. posterior probabilities. That is, you need to predict (data.rf, newdata, type = "prob").

predicting with type = "response" already gives you the "hardened" factor as output. Thus, your working point is implicitly fixed already. With respect to that, your plot is correct.


side note: in bag prediction of random forests will be highly overoptimistic!



来源:https://stackoverflow.com/questions/19972736/plotting-a-roc-curve-from-a-random-forest-classification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!