I have trained an svm model. I would like to test it but I'm facing an error in the predict() function. For simplicity's sake, here I've split up the test and train data here in non-random 70/30 split.
library(e1071)
train <- mydata[1:9731, ]
test <- mydata[(9731+1):13901, ]
mysvm <- svm(formula = outcome ~ BW + GA, data = train, type = "C-classification", kernel = "linear", gamma = 1, cost = 2)
predict(mysvm, newdata=test)
The error message is from predict() is:
Error in names(ret2) <- rowns :
'names' attribute [4170] must be the same length as the vector [4106]
The head of the data looks like ...
> head(mydata)
BW outcome GA
1 2.00 Survived 34
2 2.81 Survived 41
3 1.85 Survived 35
4 2.23 Survived 32
5 1.21 Survived 34
6 2.91 Survived 37
This user had the same error message. Problem was that s/he wasn't using dataframes. This is not the problem in my case.
> class(test)
[1] "data.frame"
> class(train)
[1] "data.frame"
I'm not sure why this error happens or what it means. A traceback() and debug(predict) were also not helpful.