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 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.