0

I'm using e1071 Package for generating VM model and 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 I have three problems:

  1. plot command not generate any errors but also plot not showing up. Plot for 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 the number of columns of 'x'

  3. I have four columns of X and I don't know how to pass four dimention X to the SVM model.

Thanks a lot for help!

Blazej
  • 11
  • 3

1 Answers1

0

Let me try to answer your questions individually.

  1. You're attempting to plot an SVM that was only fit using 1 predictor, so your classification has been created in just 1 dimension. This is essentially just a line. This has been discussed in this thread.

  2. You are flagging an error due to an issue with your dimensions. In your model, you are only building out on 1 predictor, X1. However, when you create your testset data frame, you are also including variables X2-X4. When you attempt to predict on this testset, the function flags an error because it is attempting to fit your 1 predictor model on data with 4 predictors.

    More specifically, the error means that the center = object$x.scale$"scaled:center" object has length 1, and that x has 4 columns.

  3. An easy way to do this is to just use a formula interface

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

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

Community
  • 1
  • 1
ZachTurn
  • 636
  • 1
  • 5
  • 14