How to do it...

Let's first import the necessary Python libraries and get the dataset ready:

  1. Import the required Python libraries and classes:
import numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom sklearn.datasets import load_bostonfrom sklearn.model_selection import train_test_splitfrom sklearn.preprocessing import KBinsDiscretizerfrom feature_engine.discretisers import EqualWidthDiscretiser
  1. Let's load the predictor and target variables of the Boston House Prices dataset in a dataframe:
boston_dataset = load_boston()data = pd.DataFrame(boston_dataset.data, columns=boston_dataset.feature_names)data['MEDV'] = boston_dataset.target

The boundaries for the intervals should be learned using variables in the train set only, ...

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.