性能错误(pred,"tpr","fpr")
Error in performance(pred, "tpr", "fpr")
我正在尝试使用 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")
我无法弄清楚上面的代码有什么问题。有人可以帮忙吗?
上面的代码似乎无法访问 ROCR 包中的性能函数,这就是我看到错误的原因。
我保持其他一切不变,但按如下方式解决了问题:
perf<-ROCR::performance(pred,"tpr","fpr")
ROC 曲线现在绘制得很好!
我今天遇到了同样的问题。这是我的打印(性能):
> print(performance)
function (pred, measures, task = NULL, model = NULL, feats = NULL)
{
if (!is.null(pred))
assertClass(pred, classes = "Prediction")
measures = checkMeasures(measures, pred$task.desc)
res = vnapply(measures, doPerformanceIteration, pred = pred,
task = task, model = model, td = NULL, feats = feats)
setNames(res, extractSubList(measures, "id"))
}
<bytecode: 0x0000000024d441e0>
<environment: namespace:mlr>
所以看起来 mlr 是在 performance() 上与 ROCR 有冲突的库
我正在尝试使用 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")
我无法弄清楚上面的代码有什么问题。有人可以帮忙吗?
上面的代码似乎无法访问 ROCR 包中的性能函数,这就是我看到错误的原因。
我保持其他一切不变,但按如下方式解决了问题:
perf<-ROCR::performance(pred,"tpr","fpr")
ROC 曲线现在绘制得很好!
我今天遇到了同样的问题。这是我的打印(性能):
> print(performance)
function (pred, measures, task = NULL, model = NULL, feats = NULL)
{
if (!is.null(pred))
assertClass(pred, classes = "Prediction")
measures = checkMeasures(measures, pred$task.desc)
res = vnapply(measures, doPerformanceIteration, pred = pred,
task = task, model = model, td = NULL, feats = feats)
setNames(res, extractSubList(measures, "id"))
}
<bytecode: 0x0000000024d441e0>
<environment: namespace:mlr>
所以看起来 mlr 是在 performance() 上与 ROCR 有冲突的库