...
/Random Search Using the Random Forest Algorithm
Random Search Using the Random Forest Algorithm
Learn how to apply the random search method to find the best hyperparameters for a random forest model.
A practical example of the random search method
This is the second example of how we can use the random search method to optimize the hyperparameters of the ML model.
In this second example, we’ll use the random forest algorithm to determine which combination of hyperparameter values will produce the best results compared to the results obtained by using the default values for the hyperparameters.
What will we learn?
In the Jupyter Notebook, we’ll learn to:
Create and train an ML model (random forest regression).
Measure the performance of the ML model.
Perform the steps required to implement the random search method.
Identify a combination of hyperparameters that provide the best results.
Import important packages
First, we import the important Python packages that will do the following tasks:
Create and train an ML model (random forest algorithm).
Check the ML model’s performance.
Implement the random search method.
Identify a combination of hyperparameters that provide the best results.
# import important modulesimport numpy as npimport pandas as pd# sklearn modulesfrom sklearn.ensemble import RandomForestClassifierfrom sklearn.metrics import f1_scorefrom sklearn.model_selection import cross_val_scorefrom sklearn.preprocessing import MinMaxScalerimport warningswarnings.filterwarnings("ignore")# seedingnp.random.seed(123)