If you want to construct a transformer from an arbitrary callable, use the FunctionTransformer
class in scikit-learn.
The FunctionTransformer
enables integrating your custom function seamlessly into scikit-learn’s pipeline framework, making it easier to build complex preprocessing workflows and ensure consistent application of transformations across different datasets.