Let's take an example of the diamond dataset to understand hyperparameter tuning in scikit-learn.
To perform hyperparameter tuning, we first have to import the libraries that we will use. To import the libraries, we will use the following code:
import numpy as npimport matplotlib.pyplot as pltimport pandas as pdfrom sklearn.metrics import mean_squared_error%matplotlib inline
Then, we perform the transformations to the diamond dataset that we will use in this example. The following shows the code used to prepare data for this dataset:
# importing datadata_path= '../data/diamonds.csv'diamonds = pd.read_csv(data_path)diamonds = pd.concat([diamonds, pd.get_dummies(diamonds['cut'], prefix='cut', drop_first=True)],axis=1) ...