Finding the optimal hyperparameters through a grid search

Finding the best hyperparameters (they are called this because they influence the parameters learned during the training phase) is not always easy, and there are seldom good methods to start from. Personal experience (a fundamental element) must be aided by an efficient tool, such as GridSearchCV, which automates the training process of different models and provides the user with optimal values using cross-validation.

As an example, we show how to use grid search to find the best penalty and strength factors for logistic regression based on the Iris dataset:

import multiprocessingfrom sklearn.datasets import load_irisfrom sklearn.model_selection import GridSearchCViris = load_iris() ...

Get Machine Learning Algorithms - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.