Let`s build a SVM linear core using the sklearn Python library and the Iris dataset found in the Python dataset library.
Linear Kernel is used when the data is linearly separable, that is, it can be separated with a single line. This is one of the most common kernels. It is mainly used when there are a large number of functions in a given dataset. One example where there are many features is text classification , as each alphabet is a new feature. Therefore, we mainly use the linear kernel in text classification.
Note . Internet connection must be stable while running the code below as it is related to data loading.
In the image above, there are two sets of features: Blue and Yellow . Since they can be easily separated, or in other words, they are linearly separable, so a linear kernel can be used here.
Advantages of using a linear kernel:
1. Training SVM with a linear kernel is faster than with any other kernel.
2. When training SVM with a linear kernel, only optimization of the C Regularization parameter is required. On the other hand, when teaching other kernels, it is necessary to optimize the γ, parameter, which means that the search in the grid usually takes longer.
Here all functions are separated using simple lines, thus representing a linear kernel.