Hyperparameter tuning in scikit-learn

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) ...

Get Mastering Predictive Analytics with scikit-learn and TensorFlow now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.