SVM modeling

We will use the e1071 package to build our SVM models. We will start with a linear support vector classifier and then move on to the nonlinear versions. The e1071 package has a nice function for SVM called tune.svm(), which assists in the selection of the tuning parameters/kernel functions. The tune.svm() function from the package uses cross-validation to optimize the tuning parameters. Let's create an object called linear.tune and call it using the summary() function, as follows:

    > linear.tune <- tune.svm(type ~ ., data = train,      kernel = "linear",      cost = c(0.001, 0.01, 0.1, 1, 5, 10))    > summary(linear.tune)    Parameter tuning of 'svm':    - sampling method: 10-fold cross validation    - best parameters:     cost        1    - best performance: ...

Get Mastering Machine Learning with R - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.