- Python Machine Learning Cookbook(Second Edition)
- Giuseppe Ciaburro Prateek Joshi
- 191字
- 2021-06-24 15:40:58
How to do it...
Let's see how to build a nonlinear classifier using SVMs:
- 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.
- If you run this code now, you will get the following:
- You will also see the following classification report printed on your Terminal:
- 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}
- Replace this line with the following one:
params = {'kernel': 'rbf'}
- If you run this code now, you will get the following:
- You will also see the following classification report printed on your Terminal: