Solving nonlinear problems using a kernel SVM
Another reason why SVMs enjoy high popularity among machine learning practitioners is that they can be easily kernelized to solve nonlinear classification problems. Before we discuss the main concept behind the so-called kernel SVM, the most common variant of SVMs, let’s first create a synthetic dataset to see what such a nonlinear classification problem may look like.
Kernel methods for linearly inseparable data
Using the following code, we will create a simple dataset that has the form of an XOR gate using the logical_xor
function from NumPy, where 100 examples will be assigned the class label 1
, and 100 examples will be assigned the class label -1
:
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> np.random.seed(1)
>>> X_xor = np.random.randn(200, 2)
>>> y_xor = np.logical_xor(X_xor[:, 0] > 0,
... X_xor[:, 1] > 0)
>>> y_xor...