...
/Sequential Model-Based Optimization using K-Nearest Neighbors
Sequential Model-Based Optimization using K-Nearest Neighbors
Learn to apply the sequential model-based optimization method (SMBO) to find the best hyperparameters for a K-nearest neighbors model.
This example shows how we can use the SMBO method to optimize the hyperparameters of the ML model.
In this example, we’ll use the k-nearest neighbors (KNN) 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 this lesson, we’ll learn how to do the following things in the Jupyter Notebook:
Create and train an ML model (KNN).
Measure the performance of the ML model.
Perform the steps required to implement the SMBO method.
Identify the combination of hyperparameters that provide the best results.
Import the important packages
First, we import the important Python packages that will perform the following tasks:
Create and train an ML model (KNN algorithm).
Check ML model performance.
Implement the SMBO method.
Identify a combination of hyperparameters that provide the best results.
# import important modulesimport numpy as npimport pandas as pd# sklearn modulesfrom sklearn.neighbors import KNeighborsClassifierfrom 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 ...