O'Reilly logo

R: Recipes for Analysis, Visualization and Machine Learning by Chiu Yu-Wei, Atmajitsinh Gohil, Shanthi Viswanathan, Viswa Viswanathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Classifying using Support Vector Machine

The e1071 package can help you to easily apply the very powerful Support Vector Machine (SVM) classification technique.

Getting ready

If you have not already installed the e1071 and caret packages, install them now. Download the data files for this chapter from the book's website and place the banknote-authentication.csv file in your R working directory. We will build an SVM model to predict class based on the other variables.

How to do it...

To classify using SVM, follow these steps:

  1. Load the e1071 and caret packages:
    > library(e1071)
    > library(caret)
  2. Read the data:
    > bn <- read.csv("banknote-authentication.csv")
  3. Convert the outcome variable class to a factor:
    > bn$class <- factor(bn$class)
  4. Partition the data:
    > set.seed(1000) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required