Building custom transformation functions

As you will have noticed, in our example, we used a couple of custom transformation functions, an identity, and an inverse, in order to have the original features along the transformed one and to make features inverse. Custom transformations can help you deal with the specific munging you have in mind for your problem, and you will also find them useful because they can act as a filter by filtering unwanted or erroneous values.

You can create a custom transformation just by applying the FunctionTransformer function from sklearn.preprocessing, which turns any function into a Scikit-learn class with the fit and transform method. Creating a transformation from scratch may help to make things clear for ...

Get Python Data Science Essentials - Third Edition now with O’Reilly online learning.

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