[R] tune an support vector machine

Uwe Bohne balu555 at gmx.de
Fri Dec 6 14:06:26 CET 2013


   Hej all,

   actually i try to tune a SVM in R and use the package "e1071" wich works
   pretty well.
   I do some gridsearch in the parameters and get the best possible parameters
   for classification.
   Here is my sample code

   type<-sample(c(-1,1) , 20, replace = TRUE )
   weight<-sample(c(20:50),20, replace=TRUE)
   height<-sample(c(100:200),20, replace=TRUE)
   width<-sample(c(30:50),20,replace=TRUE)
   volume<-sample(c(1000:5000),20,replace=TRUE)

   data<-cbind(type,weight,height,width,volume)
   train<-as.data.frame(data)
   library("e1071")

   features <- c("weight","height","width","volume")
   (formula<-as.formula(paste("type ~ ", paste(features, collapse= "+"))))

   svmtune=tune.svm(formula,  data=train, kernel="radial", cost=2^(-2:5),
   gamma=2^(-2:1),cross=10)
   summary(svmtune)

   My question is if there is a way to tune the features.

   So in other words - what i wanna do is to try all possible combinations of
   features : for example use only (volume) or use (weight, height) or use
   (height,volume,width) and so on for the SVM  and to get the best combination
   back.


   Best wishes

   Uwe


More information about the R-help mailing list