【发布时间】:2019-01-11 23:36:13
【问题描述】:
我正在尝试使用 R 中的 ROCR 包绘制 ROC 曲线,但遇到以下错误:
Error in performance(pred, "tpr", "fpr") :
Assertion on 'pred' failed: Must have class 'Prediction', but has class 'prediction'
这是我用来进行性能段调用的代码:
#convert actual and predicted labels to numeric
predicted<-as.numeric(as.character(test$Class))
actual<-as.numeric(as.character(test$overall_satisfaction))
#generate confusion matrix and label positive class
library(caret)
confusionMatrix(predicted,actual,positive="1")
混淆矩阵输出看起来很好。但是,在下一段中,ROCR 中的性能函数会引发错误,因此 ROC 曲线没有绘制出来。
#ROC curve
library(ROCR)
pred<-prediction(predicted, actual)
perf<-performance(pred,"tpr","fpr")
plot(perf,col="red", main="mlr_parameters_ROC")
abline(0,1, lty = 8, col = "grey")
我无法弄清楚上面的代码有什么问题。有人可以帮忙吗?
【问题讨论】: