Understand Support Vector Machine (SVM) by improving a simple classifier model
Do not miss this exclusive book on Binary Tree Problems. Get it now for free.
Support vector machines are a popular class of Machine Learning models that were developed in the 1990s. They are capable of both linear and non-linear classification and can also be used for regression and anomaly/outlier detection. They work well for wide class of problems but are generally used for problems with small or medium sized data sets. In this tutorial, we will start off with a simple classifier model and extend and improve it to ultimately arrive at what is referred to a support vector machine (SVM).
Hard margin classifier
A hard margin classifier is a model that uses a hyperplane to completely separate two classes. A hyperplane is a subspace with one less dimension as the ambient space.
- In two dimensions, a hyperplane is a one dimension subspace namely a line.
- In three dimensions, a hyperplane is a flat two dimension subspace namely a plane.
- In a p dimensional space, a hyperplane is a flat affine subspace of p-1 dimension.
It is helpful to consider each observation in our data set as existing in a π -dimensional space where π is the number of features (columns) in our data. A hyperplane is simply a generalization of a plane in π -dimensional spaces.Here, we plot three such hyperplanes to separate two classes.
from sklearn.datasets import make_blobs
X, y = make_blobs(centers=[[1, 1], [-1, -1]], cluster_std=0.4, random_state=0)
x = np.linspace(-2, 2, 100)
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.bwr)
plt.plot(x, -x+0.25, '--k')
plt.plot(x, -0.25*x-0.3, 'r--')
plt.plot(x, -1.5*x+1, 'b--')
plt.xlim([-2, 2])
plt.ylim([-2, 2])
plt.xlabel('$x_1
Sign up for FREE 3 months of Amazon Music. YOU MUST NOT MISS.