如何在绘制ROCR图时纠正错误?

时间:2017-05-22 08:56:58

标签: r

  

性能出错(pred,“tpr”,“fpr”):错误的参数类型:   第一个参数必须是'预测'类型;第二和可选的第三   论证必须是可用的绩效衡量标准!

s <- svm(Column20 ~ ., data =train) 
pred <- predict(s, test[,-20]) 
x <-table( pred, test$Column20) 
P <- performance(x, "tpr", "fpr")

如果我将此行代码更改为x&lt; -prediction(pred,test $ Column20),即时收到此错误

 Error in prediction(pred, test$Column20) : 
  Format of predictions is invalid.

我不明白错误。请你解释一下我做错了什么? 提前致谢

1 个答案:

答案 0 :(得分:0)

这是一个简单的说明性示例。我希望它可以帮到你。

library(e1071)
library(ROCR)

df <- iris[,1:4]
df$virgi <- as.numeric(iris$Species=="virginica")
svmMod <- svm(virgi ~ ., data = df)

svmPred <- predict(svmMod, df[,-5]) 

svmPredictiction <- prediction(svmPred, df$virgi)
svmPerf <- performance(svmPredictiction, "tpr", "fpr")

plot(svmPerf)

enter image description here