“Error in table(pred = prediction, true = W[, 8]) : all arguments must have the same length”

久未见 提交于 2019-12-10 14:50:14

问题


this is my data:

 Anon_Student_Id           Problem_Hierarchy Problem_Name Problem_View Number_Of_Steps Sum_Of_Steps_Duration Sum_Of_Hints result
1      80nlN05JQ6 Unit ES_01, Section ES_01-6         EG21            8               3                    28            0      1
2      80nlN05JQ6 Unit ES_01, Section ES_01-6         EG21            9               3                    37            0      0
3      80nlN05JQ6 Unit ES_01, Section ES_01-6         EG21           10               3                    50            0      0
4      80nlN05JQ6 Unit ES_01, Section ES_01-6         EG22            1               3                    78            0      0
5      80nlN05JQ6 Unit ES_01, Section ES_01-6         EG22            2               3                    41            0      1
6      80nlN05JQ6 Unit ES_01, Section ES_01-6         EG22            3               3                    92            0      0

I'm trying to predict the attribute "result" by SVM model :

model<-svm(result~., scale=FALSE, data=W)

prediction <- predict(model, W[,-8])

table(pred = prediction, true = W[,8])

But I get this error:

"Error in table(pred = prediction, true = W[, 8]) : 
  all arguments must have the same length"

When I checked it I got: length(pred)=2042 and length(true)=2043

Why I'm getting this error?? (I mean- why i'm getting different lengths? "pred" and "true" are supposed to have the same length)

Thanks!


回答1:


Problem solved: i got rid of all the na values of my data using na.omit(W) and then it worked. thank you!



来源:https://stackoverflow.com/questions/17155614/error-in-tablepred-prediction-true-w-8-all-arguments-must-have-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!