6. (SVM) Support Vector Machine in R language

classifying horses and mules using SVM

Let’s discuss a use case where we use SVM to classify new data as horses or mules. 

Problem statement: Classify horses and mules using height and weight as the two features. Horses and mules typically have different weights and heights, with horses being heavier and taller. 

The following are the steps to make the classification:

  1. Import the data set 
  2. Make sure you have your libraries. The e1071 library has SVM algorithms built in. Create the support vectors using the library. 
  3. Once the data is used to train the algorithm plot, the hyperplane gets a visual sense of how the data is separated. If the data is two-dimensional or three-dimensional, it will be easier to plot. 
  4. Use the trained model to classify new values. We should have a training set and a test set. Then, ingest the new data. For our example, we’re going to use the whole dataset to train the algorithm and then see how it performs. 
  5. Once you see how it performs, the algorithm will decide whether the image is a horse or a mule.

Here’s the R code: 


Leave a Reply

Your email address will not be published. Required fields are marked *