I am trying to implement leave-one-out cross-validation using Support-Vector Regression in R with the e1071 package. The data and the code I have look more or less like this:
library(e1071)
#create fake dataset
y=rpois(30,3)-4+(rbinom(30,1,0.5))/2
x1=c(rep('C',16),rep('S',14))
x2=c(runif(16,0,1),runif(14,0,1)/10)
x3=c(runif(16,0,1)/5,runif(14,0,1))
dat=data.frame(y=y,x1=x1,x2=x2,x3=x3)
train=dat[-1,]
test=dat[1,]
# train the model
model=tune(svm, train$y ~ train$x1*train$x2*train$x3,kernel='linear',
ranges = list(epsilon = seq(0.1,0.6,0.1), cost = 2^(0:9)))
model=model$best.model
#predict
predict(model,newdata=test)
The problem is that the predict function returns only the trained values and does not predict the test dataset. I have seen a similar question here, predict.svm does not predict new data, but it seems the solution does not apply to my code. Any ideas on this problem?