I prepared a svm model. I would like to test it, but I ran into an error in the pred () function. For simplicity, here I divided the test data and training here in a 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 from pred () is:
Error in names(ret2) <- rowns : 'names' attribute [4170] must be the same length as the vector [4106]
The data head 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. The problem was that he / she did not use dataframes. This is not a problem in my case.
> class(test) [1] "data.frame" > class(train) [1] "data.frame"
I am not sure why this error occurs or what it means. Tracking () and debugging (prediction) also did not help.
source share