...

/

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.

Press + to interact

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.

Press + to interact
# import important modules
import numpy as np
import pandas as pd
# sklearn modules
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import f1_score
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import MinMaxScaler
import warnings
warnings.filterwarnings("ignore")
# seeding
np.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 ...