SVM in R for regression

I have 4 data dimensions. In R, I use plot3d with the 4th dimension being a color. I would like to use SVM to find the best regression line to give me a better correlation. In principle, the optimal hyperplan corresponding to the color scheme. How can i do this?

+4
source share
2 answers

This is the main idea (of course, the specific formula will vary depending on your variable names and depends on it):

library(e1071) data = data.frame(matrix(rnorm(100*4), nrow=100)) fit = svm(X1 ~ ., data=data) 

Then you can use the regular functions summary , plot , predict , etc. on fit object. Please note that with SVM, hyper parameters usually need to be tuned for best results. you can do this with a tune wrapper. Also check out the caret package, which I think is wonderful.

+10
source

Take a look at the svm function in the e1071 package. You can also consider kernelab, klaR, or svmpath packages.

EDIT: @CodeGuy, John provided you with an example. I believe that your 4 dimensions are functions that you use to classify your data, and that you have another other variable that is a real class.

 y <- gl(4, 5) x1 <- c(0,1,2,3)[y] x2 <- c(0,5,10,15)[y] x3 <- c(1,3,5,7)[y] x4 <- c(0,0,3,3)[y] d <- data.frame(y,x1,x2,x3,x4) library(e1071) svm01 <- svm(y ~ x1 + x2 + x3 + x4, data=d) ftable(predict(svm01), y) # Tells you how your svm performance 
+5
source

Source: https://habr.com/ru/post/1379705/


All Articles