How to do it...

We will use the Boston House Prices dataset from scikit-learn. The target in this dataset is continuous, therefore, we will train a decision tree for regression with DecisionTreeRegressor() from scikit-learn:

  1. Let's import the required Python libraries, classes and dataset:
import pandas as pdimport matplotlib.pyplot as pltfrom sklearn.datasets import load_bostonfrom sklearn.model_selection import train_test_splitfrom sklearn.tree import DecisionTreeRegressorfrom feature_engine.discretisers import DecisionTreeDiscretiser
  1. Let's load the Boston House Prices dataset into a pandas dataframe:
boston_dataset = load_boston()data = pd.DataFrame(boston_dataset.data, columns=boston_dataset.feature_names)data['MEDV'] = boston_dataset.target ...

Get Python Feature Engineering Cookbook 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.