Return a new recipe with steps added after the existing ones.
The recipe itself is never changed, so a recipe can be extended in several directions from a common starting point. Steps run in the order they were added.
Step ids are kept unique within the recipe. A step that did not get an explicit id and whose default collides with an earlier step’s is added under a suffixed id instead ("dummy", then "dummy_2"), so the two are addressable separately. Passing an id that a step already in the recipe uses raises ValueError.
Parameters
*steps: Step
-
The steps to add, in order.
Examples
Each add() returns a new recipe, so steps chain into a pipeline without mutating the original:
recipe = (
Recipe()
.add(StepNormalize(s.numeric_features()))
.add(StepDummy(s.nominal_features()))
)
recipe
Recipe (untrained)
Inputs: no roles assigned
Steps:
step_normalize(select(role='feature', type=NumericType)) [untrained]
step_dummy(select(role='feature', type=(String, Categorical, Enum))) [untrained]
Adding the same kind of step twice keeps the ids distinct:
twice = recipe.add(StepNormalize(s.integer_features()))
[step.id for step in twice.steps]
['normalize', 'dummy', 'normalize_2']