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:
- 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
- Let's load the predictor variables and target from the Boston House Prices dataset:
boston_dataset = load_boston()data = pd.DataFrame(boston_dataset.data, ...