## Recipe


A declarative, untrained pipeline of feature-engineering steps.


Usage

``` python
Recipe(
    steps=None,
    *,
    data=None,
    target=None,
    features=None,
    case_weights=None,
)
```


A recipe is specified in two parts: the columns' roles are declared first (the `target`, [features](Selectors.md#mlfeatures.Selectors.features) and `case_weights` arguments, plus [set_roles()](Recipe.set_roles.md#mlfeatures.Recipe.set_roles)), then steps are added with [add()](Recipe.add.md#mlfeatures.Recipe.add). Specifying a recipe never touches data; nothing is estimated until [fit()](Step.fit.md#mlfeatures.Step.fit), which returns a [FittedRecipe](FittedRecipe.md#mlfeatures.FittedRecipe), and [FittedRecipe.transform()](FittedRecipe.transform.md#mlfeatures.FittedRecipe.transform) applies it to new data.

Each [add()](Recipe.add.md#mlfeatures.Recipe.add) returns a new recipe, so steps chain into a pipeline:


``` python
recipe = (
    Recipe(data=credit, target="Status")
    .add(StepDropCorr(s.numeric_features(), threshold=0.9))
    .add(StepNormalize(s.numeric_features()))
)
```


The untrained recipe shows the roles it carries and its steps with their selectors unresolved:


``` python
recipe
```


    Recipe (untrained)
      Inputs: 14 columns (1 target)
      Steps:
        step_drop_corr(select(role='feature', type=NumericType))  [untrained]
        step_normalize(select(role='feature', type=NumericType))  [untrained]


[set_roles()](Recipe.set_roles.md#mlfeatures.Recipe.set_roles) declares roles on the input columns, so it can be applied anywhere among the steps, including after them, with the same result (once a role operation is written before the first step, [set_roles()](Recipe.set_roles.md#mlfeatures.Recipe.set_roles) keeps the order it was written in with it, see [set_roles()](Recipe.set_roles.md#mlfeatures.Recipe.set_roles)):


``` python
late = (
    Recipe(data=credit)
    .add(StepDropCorr(s.numeric_features(), threshold=0.9))
    .add(StepNormalize(s.numeric_features()))
    .set_roles(target="Status")
)
late
```


    Recipe (untrained)
      Inputs: 14 columns (1 target)
      Steps:
        step_drop_corr(select(role='feature', type=NumericType))  [untrained]
        step_normalize(select(role='feature', type=NumericType))  [untrained]


To change a role part way through the pipeline instead, use [add_role()](Recipe.add_role.md#mlfeatures.Recipe.add_role), [update_role()](Recipe.update_role.md#mlfeatures.Recipe.update_role) or [remove_role()](Recipe.remove_role.md#mlfeatures.Recipe.remove_role), which take effect from where they are written.


## Parameters


`steps: list[Step] | None = None`  
Steps to start from, equivalent to chaining [add()](Recipe.add.md#mlfeatures.Recipe.add) once per step. Default `None` (no steps).

`data: DataFrame | None = None`  
A data frame whose column names are used to check role assignments as soon as they are made, and which backs [summary()](Recipe.summary.md#mlfeatures.Recipe.summary) before fitting. Nothing is estimated from it and it is never modified, so a small sample with the right columns is enough. Default `None`.

`target: str | list[str] | None = None`  
Column name or list of names to give the `"target"` role. Default `None`.

`features: str | list[str] | None = None`  
Column name or list of names to give the `"feature"` role. With the default, `None`, every column that is not a target or a case weight becomes a feature when the recipe is fitted, including columns given a custom role with [set_roles()](Recipe.set_roles.md#mlfeatures.Recipe.set_roles). Pass names to choose the features yourself and keep such columns out.

`case_weights: str | list[str] | None = None`  
Column name or list of names to give the `"case_weights"` role. Default `None`.
