O'Reilly logo

Mastering Predictive Analytics with scikit-learn and TensorFlow by Alan Fontaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required