Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

predict with kernlab package error Error in .local(object, ...) : test vector does not match model R

Tags:

r

predict

kernlab

I'm testing the kernlab package in a regression problem. It seems it's a common issue to get 'Error in .local(object, ...) : test vector does not match model ! when passing the ksvm object to the predict function. However I just found answers to classification problems or custom kernels that are not applicable to my problem (I'm using a built-in one for regression). I'm running out of ideas here, my sample code is:

data <- matrix(rnorm(200*10),200,10)
tr <- data[1:150,]
ts <- data[151:200,]

mod <- ksvm(x = tr[,-1],
            y = tr[,1],
            kernel = "rbfdot", type = 'nu-svr',
            kpar = "automatic", C = 60, cross = 3)

pred <- predict(mod, 
                ts
                )
like image 958
nopeva Avatar asked Sep 24 '13 18:09

nopeva


1 Answers

You forgot to remove the y variable in the test set, and so it fails because the number of predictors don't match. This will work:

predict(mod,ts[,-1])
like image 172
nograpes Avatar answered Oct 12 '22 07:10

nograpes