tuning svm parameters in R (linear SVM kernel)

28,205

From ETHZ: best.svm() is really just a wrapper for tune.svm(...)$best.model. The help page for tune() will tell you more on the available options.

Be sure to also go through the examples on the help page for tune(). e1071::svm offers linear, radial (the default), sigmoid and polynomial kernels, see help(svm). For example, to use the linear kernel the function call has to include the argument kernel = 'linear':

data(iris)
obj <- tune.svm(Species~., data = iris, 
                cost = 2^(2:8), 
                kernel = "linear") 

If you are new to R and would like to train and cross validate SVM models you could also check the caret package and its train function which offers multiple types of kernels. The whole 'topics' section on that site might be of interest, too.

Share:
28,205
aceminer
Author by

aceminer

Updated on May 12, 2020

Comments

  • aceminer
    aceminer almost 4 years

    what is the difference between tune.svm() and best.svm().

    When we tune the parameters of svm kernel, aren't we expected to always choose the best values for our model.

    Pardon as i am new to R and machine learning.

    I noticed that there was no linear kernel option in tuning svm. Is there a possibility to tune my svm using a linear kernel

  • aceminer
    aceminer over 9 years
    I checked and theres no parameter for selection of kernel. It threw up an error for me
  • thie1e
    thie1e over 9 years
    Which function threw the error? As in the example above, the kernel selection works in tune.svm.
  • aceminer
    aceminer over 9 years
    think it was a typo. Its working fine now thanks a lot.