recipe = Recipe(data=credit).set_roles(
target="Status", feature=["Age", "Income", "Home"]
)
recipeRecipe (untrained)
Inputs: 14 columns (3 features, 1 target)
Steps:
<none>
Return a new recipe with the given role assignments added.
Usage
Standard roles have dedicated keyword arguments; arbitrary custom roles may be passed as additional keywords. Each value is a column name or a list of names. Assignments are added to any roles the recipe already carries, so a column may end up with several roles at once; incompatible combinations (e.g. target + feature on one column) are rejected. When the recipe was built with a prototype data frame, every name is checked against it; without a prototype there is nothing to check against, so any name is accepted and typos surface later, when the recipe is fitted.
Roles are what let a step say “all numeric features” without also picking up the target or case weights: selectors such as Selectors.numeric_features() only match columns carrying the feature role. Declare feature explicitly to keep other columns, such as an ID, out of those selections. A custom role marks columns for your own selectors, or for update_role_requirements.
Roles apply to the columns of the input data, whatever the call’s position among the steps. Columns that steps create get their roles from the step that creates them. set_roles() only adds roles; to add, change, or remove one part way through the pipeline, use add_role, update_role or remove_role. Next to those written before the first step, which also act on the input columns, it keeps the order it was written in, so update_role("x", new_role="id").set_roles(group="x") leaves x with both roles, while the same two calls the other way round leave it with "id" only. A custom role can be selected in a step with Selectors.has_role().
The roles property returns a copy of the roles the recipe starts from: what the constructor and set_roles() declared, with any role operation written before the first step applied (default features are not shown). Changing the copy does not change the recipe; summary() shows the same roles per column.
target: str | list[str] | None = NoneColumn(s) to assign the "target" role. Default None.
feature: str | list[str] | None = NoneColumn(s) to assign the "feature" role. Default None.
case_weights: str | list[str] | None = NoneColumn(s) to assign the "case_weights" role. Default None.
**custom: str | list[str]group="city"). The constructor’s plural features= is rejected here rather than silently becoming a custom role.
Assigning roles returns a new recipe, leaving the original untouched:
Recipe (untrained)
Inputs: 14 columns (3 features, 1 target)
Steps:
<none>
Custom roles are just extra keywords, and stack with the roles a column already has: