Implementing Grid Search
To implement Grid Search (see Chapter 3, Exploring Exhaustive Search), we can actually write our own code from scratch since it is just a simple nested for loop
that tests all of the possible hyperparameter values in the search space. However, by using sklearn
’s implementation of Grid Search, GridSearchCV
, we can have a cleaner code since we just need to call a single line of code to instantiate the class.
Let’s walk through an example of how we can utilize GridSearchCV
to perform Grid Search. Note that, in this example, we are performing hyperparameter tuning on an RF model. We will utilize sklearn’s
implementation of RF, RandomForestClassifier
. The dataset used in this example is the Banking Dataset – Marketing Targets provided on Kaggle (https://www.kaggle.com/datasets/prakharrathi25/banking-dataset-marketing-targets).
Original Data Source
This data was first published in A Data-Driven Approach to Predict the Success...