Performing discretization followed by categorical encoding

After discretization, the intervals of the variable can be treated as a discrete numerical variable, or as categories in a categorical variable. If treated as categorical, we can follow up the discretization by reordering the intervals according to the target value, as we did in the Encoding with integers in an ordered manner recipe in Chapter 3, Encoding Categorical Variables, to create a monotonic relationship between the intervals and the target. In this recipe, we will combine these two feature engineering techniques using Feature-engine and the Boston House Prices dataset from scikit-learn.

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.