That is the place the true magic occurs. Within the rework()
methodology, you outline the logic for the way your information shall be reworked. It’s anticipated to take an enter X
and return a reworked model of it.
Make sure that the rework()
methodology returns an array-like object of the identical form because the enter, which scikit-learn
expects. If you wish to return a special form, then this it is perhaps extra related to implement a custom feature selector.
Instance: A Customized Log Transformer
Let’s say you wish to create a customized transformer that applies a logarithmic transformation to your information.
This LogTransformer
takes an offset
parameter to keep away from taking the logarithm of zero or damaging numbers.
Utilizing the Customized Transformer in a Pipeline
You’ll be able to seamlessly combine your customized transformer into an scikit-learn
pipeline, similar to any of the built-in transformers.
Conclusion
Implementing a customized transformer in scikit-learn
entails simply three steps:
1. Subclass
BaseEstimator
andTransformerMixin
.2. Outline the
match()
methodology (if studying is critical).3. Outline the
rework()
methodology to use your customized transformation.
By following these steps, you may create versatile, reusable transformations that match completely into scikit-learn
‘s pipeline system.