...
/Random Search Using Logistic Regression
Random Search Using Logistic Regression
Learn how to apply the random search method to find the best hyperparameters for a logistic regression model.
A practical example of a random search method
This is the first example of how we can use the random search method to optimize the hyperparameters of the ML model.
In this first example, we’ll use the logistic regression algorithm to determine which combination of hyperparameter values will produce the best results in comparison 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 (logistic regression).
Measure the performance of the ML model.
Perform the steps required to implement the random search method.
Identify the combination of hyperparameters that provide the best results.
Import important packages
First, we’ll import the important Python packages that will do the following tasks:
Create and train an ML model (logistic regression).
Check the ML model’s performance.
Implement the random search method.
Identify the combination of hyperparameters that provide the best results.
# import important modulesimport numpy as npimport pandas as pd# sklearn modulesfrom sklearn.linear_model import LogisticRegressionfrom sklearn.metrics import f1_scorefrom sklearn.model_selection import cross_val_scorefrom sklearn.preprocessing import MinMaxScalerimport warningswarnings.filterwarnings("ignore")# seedingnp.random.seed(123)
Note: The procedure for dataset preparation has been explained in detail in the Data Preparation lesson. Please refer to the lesson to gain insights into how the ...