How it works...
In this recipe, we replaced the categories with integers according to the target mean value using pandas and Feature-engine.
We first loaded the dataset and divided it into train and test sets. In the first part of the recipe, we worked with the categorical A7 variable. We plotted the mean target value per A7 category. With pandas' groupby() method, we grouped the data per category of A7, and next with pandas' mean() method, we determined the mean value of the target, A16, for each of the categories of A7. We followed up with pandas' plot() method to create a plot of category versus target mean value. We added a title and y labels with Matplotlib's title() and ylabel() methods.
To perform the encoding, we first determined ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access