How to do it...

Let's see how to find optimal hyperparameters:

  1. The full code is given in the file that's already provided to you. We start importing the libraries:
from sklearn import svmfrom sklearn import model_selectionfrom sklearn.model_selection import GridSearchCVfrom sklearn.metrics import classification_reportimport pandas as pdimport utilities 
  1. Then, we load the data:
input_file = 'data_multivar.txt'X, y = utilities.load_data(input_file)
  1. We split the data into a train and test dataset:
X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y, test_size=0.25, random_state=5)
  1. Now, we will use cross-validation here, which we covered in the previous recipes. Once you load the data and split ...

Get Python Machine Learning Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.