Support Vector Machine
This is a kind of supervised machine learning model of Support Vector Machine SVM with associated learning algorithms that analyzes the data and then predicts the data pattern. This model is used for classification and regression.
It is given a set of few training examples, of two category classes. A SVM training algorithm builds a model that assigns new data to either of two classes making it a non probabilistic binary linear classifier. A SVM model has the data marked as points ( markers ) in a way that the examples of the separate categories are divided by a clear gap that is as wide as possible.
This is how the data points are distributed in this model. New data points are mapped into the same plot and predicted to which class do they belong based on which side they are plotted.
The line separating the two classes is known as “HYPER PLANE”. There are multiple hyper planes that could be drawn between the two classes such as green line, yellow line,black line, which hyper plane should be considered.
We have to choose the hyperplane that maximizes the distance between the two classes.
Now there are few data points that are touching the hyperplane and those data points are known as “SUPPORT VECTORS” , this is how the name Support vector machine name is derived.
These are the steps that should be defined when the two classes are linearly distributed , what if they are radially distributed then we have to choose “kernel trick”
Kernel trick:
Let us assume that we are a having few data points as distributed on the coordinate plot as shown below.
Now we have to draw a line that separates these classes, but drawing a line is really difficult so we have to shift to a curve.
This was one method and other method is add a plane to it, like we can shift all the blue point to another plane and draw a hyperplane between them .
This is how we can apply kernel trick.
Building a model:
Building a machine learning model based on SVM:
First of all import the libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
Next we have to import our data set by using seaborn load data set method.
Now visualize the data using seaborn or matplot .
Now let us divide the data set into independent variables and dependent variables.
Here our target variable is “species” there are three types of species.
Now let us split the model into test and train part.
Now let us train the model. But before we have to import the “support vector machine” class.
from sklearn.svm import SVC
Let us predict the values of Y_test and evaluate our model.
This shows that our model has really performed well. This is the end of this tutorial about SVM