Skip to main content

minimize()

Return a FittedRecipe that keeps only what transform() needs.

Usage

Source

minimize(recipe)

Each step decides what it can drop: a step that keeps something only for inspection after fitting, or only because fitting needed it, returns a lighter version of itself that transforms identically. A step that has nothing to drop is kept as is, shared with recipe rather than copied, and recipe itself is never modified. The roles, schema, and lineage are kept, so the minimized recipe still validates new data at the boundary and reports its lineage.

Call it before to_dict, to_json, or to_yaml when the recipe is going to be shipped with a model, so the saved file carries only what scoring needs; the writers save the recipe as it is and do not minimize it. No shipped step currently holds anything to drop, so today the result is an equivalent recipe.

Parameters

recipe: FittedRecipe
The fitted recipe to minimize.

Returns

FittedRecipe
A new recipe with each step minimized.

Examples

recipe = Recipe().add(StepNormalize(s.numeric_features()))
fitted = recipe.fit(credit)
small = minimize(fitted)
small.transform(credit).head()
shape: (5, 14)
StatusSeniorityHomeTimeAgeMaritalRecordsJobExpensesIncomeAssetsDebtAmountPrice
strf64strf64f64strstrstrf64f64f64f64f64f64
"good"0.104473"rent"0.911743-0.630317"married""no""freelance"0.887353-0.157881-0.541693-0.313105-0.501373-0.997081
"good"1.086074"rent"0.9117431.909999"widow""no""fixed"-0.404875-0.133084-0.541693-0.313105-0.0657050.344189
"bad"0.227173"owner"-0.7385060.821292"married""yes""freelance"1.7660690.722397-0.220497-0.3131052.1126372.536142
"good"-0.999828"rent"0.911743-1.17467"single""no""fixed"0.3704620.499228-0.274029-0.313105-0.283539-0.205864
"good"-0.999828"rent"-0.738506-0.993219"single""no""fixed"-0.508253-0.430643-0.541693-0.313105-1.56876-0.891365