Implementing a SVM
Implementing the SVM is actually fairly easy. We can simply create a new model and call .fit() on our training data.
To score our data we will use a useful tool from the sklearn module.
And that is all we need to do to implement our SVM, now we can run the program and take note of our amazing accuracy!
Wait... Our accuracy is close to 60% and that is horrible! Looks like we need to add something else.
Adding a Kernel
The reason we received such a low accuracy score was we forgot to add a kernel! We need to specify which kernel we should use to increase our accuracy.
We will use linear for this data-set.
After running this we receive a much better accuracy of close to 98%
Changing the Margin
By default our kernel has a soft margin of value 1. This parameter is known as C. We can increase C to give more of a soft margin, we can also decrease it to 0 to make a hard margin. Playing with this value should alter your results slightly.
If you want to play around with some other parameters have a look here.
Comparing to KNearestNeighbors
If we want to see how this algorithm runs in comparison to KNN we can run the KNN classifier on this data-set and compare our accuracy values.
To change to the KNN classifier is quite simple.
Note that KNN still does well on this data set but hovers around the 90% mark.