Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVM in R for regression

Tags:

r

svm

I have 4 dimensions of data. In R, I'm using plot3d with the 4th dimension being color. I'd like to now use SVM to find the best regression line to give me the best correlation. Basically, a best fit hyperplane dependent on the color dimension. How can I do this?

like image 718
CodeGuy Avatar asked Dec 07 '22 18:12

CodeGuy


1 Answers

This is the basic idea (of course the specific formula will vary depending on your variable names and which is the dependent):

library(e1071)

data = data.frame(matrix(rnorm(100*4), nrow=100))

fit = svm(X1 ~ ., data=data)

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

like image 182
John Colby Avatar answered Dec 09 '22 06:12

John Colby