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:
- plot command not generate errors plot not showing up. plot plot(my_data) show properly.
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'
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.
you're attempting plot svm fit using 1 predictor, classification has been created in 1 dimension. line. has been discussed in this thread.
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.an easy way use formula interface
model <- svm(kupno ~., data=my_data)
the
~.
tells model regress on all columns in data set.