Support Vector Machines (SVM)
SVM stands for a support vector machine. SVM's are typically used for classification tasks similar to what we did with K Nearest Neighbors. They work very well for high dimensional data and are allow for us to classify data that does not have a linear correspondence. For example classifying a data set like the one below.
Attempting to use K Nearest Neighbors to do this would likely give us a very low accuracy score and is not favorable. This is where SVM's are useful.
Before we start we need to import a few things from sklearn.
In previous tutorials we did quite a bit of work to load in our data sets from places like the UCI Machine Learning Repository. That is a very useful skill and is something you will often have to do when applying these algorithm to your own data. However, now that we have learned this we will use the data sets that come with sklearn. These are much nicer to work with and have some nice methods that make loading in data very quick.
For this tutorial we will be using a breast cancer data set. It consists of many features describing a tumor and classifies them as either cancerous or non cancerous.
To load our data we will simply do the following.
To see a list of the features in the data set we can do:
Similarly for the labels.
The output should look like this.
Now that we have loaded in our data set it is time to split it into training and testing data. We will do this like seen in previous tutorials.
If we want to have a look at our data we can print the first few instances.
The next tutorial will explain how a SVM works and the math behind it. Following that I will go over implementing the algorithm.