根据随机森林分类绘制ROC曲线 [英] Plotting a ROC curve from a random forest classification
问题描述
我正在尝试绘制随机森林分类的ROC曲线。进行绘图是可行的,但是我认为我正在打印错误的数据,因为生成的绘图仅具有一个点(精度)。
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).
这是我使用的代码:
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")
推荐答案
要绘制运行曲线的接收器,您需要移交分类器的连续输出,例如后验概率。也就是说,您需要进行预测(data.rf,newdata,类型= prob
)。
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"
).
<带有 type = response
的code>预测已经为您提供了强化因素作为输出。因此,您的工作点已经隐式地固定了。
predict
ing 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!
这篇关于根据随机森林分类绘制ROC曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!