r - SVM model error when creating prediction -


i'm using e1071 package generating vm model , predictions in r. my_data csv file sample:

kupno,x1,x2,x3,x4 0,1,22,1,4.961566871 1,2,18,0,6.316553966 ... 10000 lines 

my r code:

library(e1071)  model <- svm(data = my_data, y = my_data['kupno'], x = my_data['x1']) plot(model,data=my_data,fill=true) index <- 1:nrow(my_data) testindex <- sample(index, trunc(length(index)/3)) testset <- my_data[testindex,] trainset <- my_data[-testindex,] model <- svm(data = my_data, y = my_data['kupno'], x = my_data['x1']) prediction <- predict(model, testset) 

and have 3 problems:

  1. plot command not generate errors plot not showing up. plot plot(my_data) show properly.
  2. last command return error:

    'scale.default(newdata[, object$scaled, drop = false], center = object$x.scale$"scaled:center", ': length of 'center' must equal number of columns of 'x'

  3. i have 4 columns of x , don't know how pass 4 dimention x svm model.

thanks lot help!

let me try answer questions individually.

  1. you're attempting plot svm fit using 1 predictor, classification has been created in 1 dimension. line. has been discussed in this thread.

  2. you flagging error due issue dimensions. in model, building out on 1 predictor, x1. however, when create testset data frame, including variables x2-x4. when attempt predict on testset, function flags error because attempting fit 1 predictor model on data 4 predictors.

    more specifically, error means center = object$x.scale$"scaled:center" object has length 1, , x has 4 columns.

  3. an easy way use formula interface

    model <- svm(kupno ~., data=my_data)

    the ~. tells model regress on all columns in data set.