Solved – e1071 svm predict – missing predictions

missing datarsvm

I use the following code

m <- svm(x_train, y_train)
current_class_prediction <- predict(m, x_cv)

but predict returns 999 predictions instead of 1000:

> length(current_class_prediction)
[1] 999
> dim(x_cv)
[1] 1000   70

What can explain this problem?

Best Answer

It seems you have missing values in your predictors. I can reproduce this behavior with the following example:

R> library(e1071)
R> data(iris)
R> model <- svm(Species ~ ., data = iris)
R> length(predict(model, iris))
[1] 150
R> tmp <- iris
R> tmp[1, "Sepal.Length"] <- NA
R> length(predict(model, tmp))
[1] 149
Related Question