在表格(pred = prediction, true = W[, 8])中出现错误:所有参数必须具有相同的长度。

5

这是我的数据:

 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

我正在尝试使用SVM模型来预测属性“result”:

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

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

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

但是我得到了这个错误:

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

当我检查时,输出的结果为:pred长度为2042,而true长度为2043。

为什么会出现这个错误?(也就是说,为什么pred和true的长度不同?它们应该具有相同的长度)

谢谢!


2
也许我错过了什么,但2042!= 2043,不是吗? - agstudy
当然,但为什么我得到了不同的长度? - Mariel
1
@agstudy 显然2042 == 2043,误差在可接受范围内。 @OP:你的数据集中可能有一个NA值。predict函数应该会给出一个NA预测,但有可能是完全忽略了这种情况。请发布您用于拟合SVM的软件包。 - Hong Ooi
@HongOoi :) 很好的观点!我猜是 e1071 包。 - agstudy
是的,我正在使用e1071包。 - Mariel
显示剩余2条评论
1个回答

5
问题已解决: 我使用na.omit(W)清除了数据中的所有na值,然后它就可以工作了。 谢谢!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接