How to do it...

Let's see how to build a nonlinear classifier using SVMs:

  1. For the first case, let's use a polynomial kernel to build a nonlinear classifier. In the same Python file (svm.py), search for the following line:
params = {'kernel': 'linear'} 

Replace this line with the following:

params = {'kernel': 'poly', 'degree': 3} 

This means that we use a polynomial function with degree as 3. If we increase the degree, this means we allow the polynomial to be curvier. However, curviness comes at a cost, in the sense that it will take more time to train because it's more computationally expensive.

  1. If you run this code now, you will get the following:

  1. You will also see the following classification report printed on your Terminal:
  1. We can also use a radial basis function kernel to build a nonlinear classifier. In the same Python file, search for the following line:
params = {'kernel': 'poly', 'degree': 3} 
  1. Replace this line with the following one:
params = {'kernel': 'rbf'} 
  1. If you run this code now, you will get the following:

  1. You will also see the following classification report printed on your Terminal: