Issues while using predict in kernlab SVM
I am trying to predict using a trained SVM model:
eval1_rbf <- predict(SVM_rbf01, newdata = mnist_test, type = "response")
I am getting an error :'
Error in .local(object, ...) : test vector does not match model !
I have made sure that the columns of my training data and testing data is an exact match. Have also tried other solutions on stackoverflow with no luck.
What is going wrong here?
Data and Code: mnist_train: originally had 785 columns, this has been reduced to 81 columns with 80 PCs
label PC1 PC2 ...... 1 -17.8 9.8 2 4.2 -0.7
mnist_test: same columns as mnist_train
mnist_train$label <- factor(mnist_train$label) mnist_test$label <- factor(mnist_test$label) idx0 <- which(mnist_train$label == 0) idx1 <- which(mnist_train$label == 1) train01 = mnist_train[c(idx0,idx1), ] train01$label <- factor(train01$label) SVM_rbf01 <- ksvm(label ~ ., data = train01, scaled =F, kernel = 'rbfdot',C = 10,kpar = list(sigma = .00000001))