Prerequisite: SVM
Let's create a
Linear Kernel SVM using the sklearn library of Python and the
Iris Dataset that can be found in the dataset library of Python.
Linear Kernel is used when the data is Linearly separable, that is, it can be separated using a single Line. It is one of the most common kernels to be used. It is mostly used when there are a Large number of Features in a particular Data Set. One of the examples where there are a lot of features, is
Text Classification, as each alphabet is a new feature. So we mostly use Linear Kernel in Text Classification.
Note: Internet Connection must be stable while running the below code because it involves downloading data.
👁 Image
In the above image, there are two set of features "
Blue" features and the "
Yellow" Features. Since these can be easily separated or in other words, they are linearly separable, so the Linear Kernel can be used here.
Advantages of using Linear Kernel:
1. Training a SVM with a Linear Kernel is
Faster than with any other Kernel.
2. When training a SVM with a Linear Kernel, only the optimisation of the
C Regularisation parameter is required. On the other hand, when training with other kernels, there is a need to optimise the
γ parameter which means that performing a grid search will usually take more time.
Output:
👁 Image
Here all the features are separated using simple lines, thus representing the Linear Kernel.