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(, columns=boston_dataset.feature_names)data['MEDV'] =

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 live online training, plus books, videos, and digital content from nearly 200 publishers.