Skip to main content

Recipe.remove_role()

Return a new recipe with a role removed at this point in the chain.

Usage

Source

Recipe.remove_role(
    columns,
    *,
    role,
)

Takes effect where it is written (see add_role()). Every selected column must carry the role, or fitting raises ValueError. A column left with no role is kept, but role selectors no longer match it.

Parameters

columns: Selector

Columns to remove the role from. Accepts a single column name, a list of names, a mlfeatures selector such as Selectors.numeric_features() (see Selectors for the full set), or a narwhals or polars selector (narwhals.selectors.numeric(), polars.selectors.numeric()). Selectors are resolved against the data frame as the steps before this one left it, when the recipe is fitted.

role: str
The role to remove.

Examples

recipe = (
    Recipe(data=credit, target="Status")
    .add(StepNormalize(s.numeric_features()))
    .remove_role(s.starts_with("Senior"), role="feature")
)
recipe
Recipe (untrained)
  Inputs: 14 columns (1 target)
  Steps:
    step_normalize(select(role='feature', type=NumericType))  [untrained]
    remove_role(starts_with('Senior'), role='feature')

Fitting applies the change, which the summary then shows:

fitted = recipe.fit(credit)
fitted.summary()
shape: (14, 5)
namedtyperolessourcesparse
strstrstrstrbool
"Status""str""target""original"false
"Seniority""float""""original"false
"Home""str""feature""original"false
"Time""float""feature""original"false
"Age""float""feature""original"false
……………
"Income""float""feature""original"false
"Assets""float""feature""original"false
"Debt""float""feature""original"false
"Amount""float""feature""original"false
"Price""float""feature""original"false