Day-12: Kernel SVM (Non-Linear SVM)

Samet Girgin
PursuitOfData
Published in
2 min readJul 30, 2019

--

The last notes for SVM. The first day is the day to intuitively understand the SVM and look at some math behind it. The second day is to implement the linear SVM on Python and the third day is to implement the kernel support vector machine on Python.

In the beginning, the implementation is so similar to linear or simple SVM. The difference is to select any kernel function like RBF(gaussian), polynomial, sigmoid and etc instead of a linear and 1-degree model. Kernel function takes as its inputs vectors in the original space and returns the dot product of the vectors in the feature space and this is called kernel function.

# Fitting Kernel SVM to the Training setfrom sklearn.svm import SVC
classifier = SVC(kernel = ‘rbf’, random_state = 0)
classifier.fit(X_train, y_train)

Non-linear transformation is to make a dataset higher-dimensional space (Mapping a higher dimension). And it is also the fundamental of a non-linear system. The below graph reveals a non-linear dataset and how it can not be used Linear kernel rather than the Gaussian kernel.

C = 1.0  # SVM regularization parameter
svc = svm.SVC(kernel='linear', C=C).fit(X, y)
rbf_svc = svm.SVC(kernel='rbf', gamma=0.7, C=C).fit(X, y)
poly_svc = svm.SVC(kernel='poly', degree=3, C=C).fit(X, y)
lin_svc = svm.LinearSVC(C=C).fit(X, y)

In geometry, a hyperplane is a subspace whose dimension is one less than that of its ambient space. If space is 3-dimensional then its hyperplanes are the 2-dimensional planes, while if space is 2-dimensional, its hyperplanes are the 1-dimensional lines. This notion can be used in any general space in which the concept of the dimension of a subspace is defined. (Source: Wikipedia)

Mapping Function makes 2D to 3D and Projection returns the 3D to 2D

You can reach a Kernel SVM practice on Python from the Github link below. That’s all for this topic. Please follow me from my Twitter, Linkedin and Medium pages. Have a good ML journey.

--

--

Samet Girgin
PursuitOfData

Data Analyst, Petroleum & Natural Gas Engineer, PMP®