我正在使用 R 包 randomForest 创建一个可分为三组的模型。
model = randomForest(formula = condition ~ ., data = train, ntree = 2000,
mtry = bestm, importance = TRUE, proximity = TRUE)
Type of random forest: classification
Number of trees: 2000
No. of variables tried at each split: 3
OOB estimate of error rate: 5.71%
Confusion matrix:
lethal mock resistant class.error
lethal 20 1 0 0.04761905
mock 1 37 0 0.02631579
resistant 2 0 9 0.18181818
我试过几个库。例如,使用 ROCR,您不能进行三个分类,只能进行两个分类。看哪:
pred=prediction(predictions,train$condition)
Error in prediction(predictions, train$condition) :
Number of classes is not equal to 2.
ROCR currently supports only evaluation of binary classification
tasks.
来自 model$votes 的数据如下所示:
lethal mock resistant
3 0.04514364 0.952120383 0.002735978
89 0.32394366 0.147887324 0.528169014
16 0.02564103 0.973009447 0.001349528
110 0.55614973 0.433155080 0.010695187
59 0.06685633 0.903271693 0.029871977
43 0.13424658 0.865753425 0.000000000
41 0.82987552 0.033195021 0.136929461
86 0.32705249 0.468371467 0.204576043
87 0.37704918 0.341530055 0.281420765
........
我可以使用 pROC 包以这种方式获得一些非常丑陋的 ROC 图:
predictions <- as.numeric(predict(model, test, type = 'response'))
roc.multi <- multiclass.roc(test$condition, predictions,
percent=TRUE)
rs <- roc.multi[['rocs']]
plot.roc(rs[[2]])
sapply(2:length(rs),function(i) lines.roc(rs[[i]],col=i))
但是没有办法平滑这些线条,因为它们不是曲线,因为它们每个有 4 个左右的点。
我需要一种方法来为这个模型绘制一条漂亮的平滑 ROC 曲线,但我似乎找不到。有谁知道一个好的方法?首先十分感谢!