How to do it...

To perform equal-frequency discretization followed by ordering the intervals according to the target mean, we need to import from Feature-engine the EqualFrequencyDiscretiser() and the OrdinalCategoricalEncoder(), among other Python libraries and classes:

  1. Import the required Python libraries and classes:
import pandas as pdimport matplotlib.pyplot as pltfrom sklearn.datasets import load_bostonfrom sklearn.model_selection import train_test_splitfrom feature_engine.discretisers import EqualFrequencyDiscretiserfrom feature_engine.categorical_encoders import OrdinalCategoricalEncoder
  1. Let's load the predictor variables and target from the Boston House Prices dataset:
boston_dataset = load_boston()data = pd.DataFrame(boston_dataset.data, ...

Get Python Feature Engineering Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.