Skip to main content

FittedRecipe.transform()

Apply each trained step, in order, to new data.

Usage

Source

FittedRecipe.transform(data)

Every step applies the statistics stored at fit time. Steps that only act on training samples (such as row filters) are skipped, as are steps whose selection matched no columns. The result is a data frame of the same type as data.

Parameters

data: DataFrame
The data frame to transform. Its columns and dtypes must match the training data; a mismatch raises an error naming the difference.

Raises

StepError
If a step fails while transforming; the error names the step and the columns it was working on.

Examples

transform() applies the trained recipe to new data, returning a data frame with the columns the recipe learned at fit time:

recipe = (
    Recipe(data=credit, target="Status")
    .add(StepNormalize(s.numeric_features()))
    .add(StepDummy(s.nominal_features()))
)
fitted = recipe.fit(credit)
result = fitted.transform(credit.head(5))
result
shape: (5, 23)
StatusSeniorityTimeAgeExpensesIncomeAssetsDebtAmountPriceHome_otherHome_ownerHome_parentsHome_privHome_rentMarital_marriedMarital_separatedMarital_singleMarital_widowRecords_yesJob_freelanceJob_othersJob_partime
strf64f64f64f64f64f64f64f64f64i8i8i8i8i8i8i8i8i8i8i8i8i8
"good"0.1044730.911743-0.6303170.887353-0.157881-0.541693-0.313105-0.501373-0.9970810000110000100
"good"1.0860740.9117431.909999-0.404875-0.133084-0.541693-0.313105-0.0657050.3441890000100010000
"bad"0.227173-0.7385060.8212921.7660690.722397-0.220497-0.3131052.1126372.5361420100010001100
"good"-0.9998280.911743-1.174670.3704620.499228-0.274029-0.313105-0.283539-0.2058640000100100000
"good"-0.999828-0.738506-0.993219-0.508253-0.430643-0.541693-0.313105-1.56876-0.8913650000100100000