【发布时间】:2020-12-15 11:21:43
【问题描述】:
我正在尝试按照 https://rpubs.com/JanpuHou/359286 的示例之一为 svm 绘制 ROC,但我的最后一行代码不断出现错误:这是我的数据集的头部 头部(数据)
growth LogSales Age LogTA CoAge CoAge2 Reg DigMkt
1 No 15.87283 45 15.32751 8 64 0 1
2 Yes 16.05044 44 15.27176 7 49 0 1
3 Yes 15.36307 32 15.20180 3 9 1 0
4 Yes 15.09644 31 14.97866 2 4 1 0
5 Yes 16.90655 59 16.58810 11 121 1 0
6 Yes 16.45457 58 15.95558 10 100 1 0
我的代码:
split = sample.split(data, SplitRatio = 0.70)
training = subset(data, split==T)
testing = subset(data, split==F)
###Making growth last to allow for variable importnce
###Fitting model
svm_Lin = svm(growth~., data = training,
kernel = "linear", cost =1, scale = T,
probability = TRUE)
##Prediction
pred = predict(svm_Lin, testing)
table(predict = pred, truth = testing$growth)
confusionMatrix(table(pred, testing$growth))
###ROC Curve
library(ROCR)
p<- predict(svm_Lin,testing, type="decision")
pr<-prediction(p, testing$growth)
pref <- performance(pr, "tpr", "fpr")
plot(pref)
当我运行这一行时:pr<-prediction(p, testing$growth) 我收到以下错误消息
Error: Format of predictions is invalid. It couldn't be coerced to a list.
感谢任何有关如何解决此问题的帮助。
【问题讨论】:
-
检查
?ROCR::prediction以了解输入的格式。很难在这里说出predict.svm的内容,但似乎格式错误。 -
谢谢,已尝试格式化,但似乎我还没有中奖。