Tuning models with grid search
Recall from Chapter 3, Classification and Regression with K-Nearest Neighbors that hyperparameters are parameters of the model that the learning algorithm does not estimate. For example, hyperparameters of our logistic regression SMS classifier include the value of the regularization term and thresholds used to remove words that appear too frequently or infrequently. In scikit-learn, hyperparameters are set through the constructors of estimators and transformers. In the previous examples, we did not set any arguments for LogisticRegression
; we used the default values for all of the hyperparameters. These default values are often a good start, but they may not produce the optimal model. Grid search is a common method for selecting the hyperparameter values that produce the best model. Grid search takes a set of possible values for each hyperparameter that should be tuned, and evaluates a model trained on each element of the Cartesian product of the sets. That...