Of the three stated purposes of pipelines, you'd get the "convenience and encapsulation" one, but not the others:
- Joint parameter selection: you don't have any parameters for this transformation.
- Safety (from data leak): your transformation is context-specific, so there is no data leakage in applying it to the entire dataset up front.
This feels like something that is the definition of the targets, and is best considered a part of the data retrieval.
transform methods to have input just
X and not
y. For the most part, you can work around that by overriding
TransformerMixin. However, nothing downstream will expect to get two return values (transformed
y), so this won't work.
You can make a little more headway with the
imbalanced-learn package, which provides its own
Pipeline with more flexible transformation syntax. The purpose there is to implement resamplers, and that throws a major issue: resamplers do not apply at prediction time.