我使用 ROCR 来衡量各种分类算法在我的数据集上的性能。虽然我可以使用以下代码示例相对轻松地检索 AUC 指标:
predictions <- predict(rfmodel, test, type="prob")
pred.obj <- prediction(predictions[,2], data$response)
rfperf <- performance(pred.obj, "tpr","fpr")
print(sprintf("random forest AUC %f", as.numeric(performance(pred.obj,"auc")@y.values)))
我在检索其他指标时遇到困难,检索其他指标(如精度、召回率、f 等)作为我可以包含在论文表格中的单个值。我尝试了以下方法:
> p <- performance(pred.obj,"prec", "rec")
> as.numeric(p@x.values)
Error: (list) object cannot be coerced to type 'double'
我可以绘制这些值,但这不是我想要的。有什么想法吗?
最佳答案
问题是输出是一个列表。尝试 as.numeric( unlist ( p@x.values) )
关于从 ROCR 预测对象中检索分类器性能指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14832460/