Use it to put a recipe in front of any scikit-learn model, so the feature engineering is trained, cross-validated, and tuned together with the model instead of being applied by hand beforehand.
Usable as a single step in a sklearn.pipeline.Pipeline:
from mlfeatures import RecipeTransformer
pipe = Pipeline([
("recipe", RecipeTransformer(recipe)),
("model", LogisticRegression()),
])
pipe.fit(X_train, y_train)
The wrapped recipe is untrained: fit() trains it, and transform() applies the trained result. The recipe is stored verbatim so that sklearn.base.clone() (and therefore cross-validation / grid search) round-trips correctly; Recipe is immutable, so this is safe.
Step hyperparameters are tunable through sklearn’s nested parameter names, keyed on step id: recipe__<step id>__<parameter>, for example GridSearchCV(pipe, {"recipe__recipe__corr__threshold": [0.8, 0.9]}) when the transformer is named "recipe" in the pipeline. A step’s id and columns are not tunable.
It implements get_feature_names_out() and therefore composes inside a sklearn.compose.ColumnTransformer and supports set_output(transform="pandas" | "polars").
Target handling. sklearn keeps X and y apart, while a recipe identifies the target by its "target" role. At fit time y is joined onto X under the recipe’s target column name, and transform() returns the feature columns only, with the target column removed. Passing y to a recipe with no "target" role raises a ValueError, as does a recipe with more than 1 target column. A step that applies to the target column as one of its input columns (for example StepNormalize(["target"])) also raises a ValueError at fit time, because sklearn’s transform() never receives y; transform the target outside the pipeline instead (for example with sklearn.compose.TransformedTargetRegressor). A step that uses the target only at fit time, such as StepPls or StepClassDistance, is fine. With no y (an unsupervised recipe), X is used as given.