Support vector machines

Support vector machines or SVMs use a subset of training data, specifically data points near the edge of each class, in order to define a separating hyperplane (in two dimensions, a line). These edge cases are called support vectors. The goal of an SVM is to find the hyperplane that maximizes the margin (distance) between the support vectors (depicted in the following figure). In order to classify nonlinear separable classes, SVMs use the kernel trick to map data in a higher dimensional space, where it can become linearly separable:

SVM margins and support vectors

If you want to learn more about the kernel trick, this is a good starting point: https://en.wikipedia.org/wiki/Kernel_method#Mathematics:_the_kernel_trick.

In scikit-learn, an SVM is implemented under sklearn.svm, both for regression with sklearn.svm.SVR and classification with sklearn.svm.SVC. Once again, we'll test the algorithm's potential using scikit-learn and the code utilized in the regression examples. Using an SVM with a linear kernel on the breast cancer dataset results in 95% accuracy and the following confusion matrix:

n = 169

Predicted: Malignant

Predicted: Benign

Target: Malignant

39

0

Target: Benign

9

121

 

On the diabetes dataset, by fine-tuning the C parameter to 1,000 during the (svr = SVR(kernel='linear', C=1e3)) object instantiation, we are able to achieve an R2 of 0.71 and an MSE of 1622.36, marginally better than the logit model.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset