Skip to main content

API Reference

Recipes

Build a recipe, then fit and apply it. The Recipe class and its methods are flattened into this section so each method appears on the reference index.

Recipe

A declarative, untrained pipeline of feature-engineering steps.

Recipe.add()

Return a new recipe with steps added after the existing ones.

Recipe.fit()

Fit each step in order on the training data.

Recipe.set_roles()

Return a new recipe with the given role assignments added.

Recipe.add_role()

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

Recipe.update_role()

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

Recipe.remove_role()

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

Recipe.update_role_requirements()

Return a new recipe overriding whether columns are required at transform.

Recipe.summary()

The input columns, before any step runs, as a tidy data frame.

Steps: numeric features

Rescale, expand, or derive new numeric columns.

StepNormalize

Center and scale numeric columns to zero mean and unit variance.

StepOrderNorm

Normalize numeric columns onto a standard normal distribution by rank.

StepRange

Scale numeric columns to a fixed range.

StepLog

Take the logarithm of numeric columns.

StepPolynomial

Replace numeric columns with their orthogonal polynomial expansion.

StepSplineNatural

Replace numeric columns with a natural cubic spline basis expansion.

StepSplineMonotone

Replace numeric columns with a monotone (I-spline) basis expansion.

StepClassDistance

Replace numeric columns with per-row distances to each class centroid.

StepGeoDistance

Add the distance from each row to a fixed reference point.

StepIntercept

Add a constant column with a fixed value.

StepInteract

Add the pairwise product of every pair of selected columns.

Steps: categorical features

Encode nominal columns as numeric ones.

StepDummy

Expand categorical columns into k-1 binary indicator columns.

StepOneHot

Expand discrete columns into k binary indicator columns.

StepOther

Collapse infrequent categorical levels into a single "other" level.

Steps: date and datetime features

Expand Date and Datetime columns into calendar-part feature columns.

StepDateFeatures

Expand Date columns into calendar-part feature columns.

StepDatetimeFeatures

Expand Datetime columns into calendar-part feature columns.

StepHoliday

Add binary indicator columns flagging named holidays and custom recurrences.

Steps: missing data

Impute missing values, or give them an explicit level.

StepImputeMean

Impute missing numeric values with the column mean.

StepImputeMedian

Impute missing numeric values with the column median.

StepImputeMode

Impute missing values with the column mode (most frequent value).

StepUnknown

Recode missing categorical levels to an explicit "unknown" level.

StepIndicateNa

Add a binary indicator column flagging missing values.

Steps: dimensionality reduction

Reduce dimensionality, or filter columns that carry no signal.

StepDropZeroVariance

Remove columns that have a single unique value (zero variance).

StepDropNearZeroVariance

Remove columns that are sparse and unbalanced (near-zero variance).

StepPca

Project numeric columns onto their principal components.

StepPls

Project numeric columns onto partial-least-squares components.

StepDropCorr

Remove numeric columns whose pairwise absolute correlation is too high.

StepDrop

Remove the selected columns.

Steps: general expressions

Arbitrary row filters and column computations; escape hatches rather than a named feature-engineering method.

StepFilter

Remove rows that do not match a predicate.

StepMutate

Apply arbitrary column expressions: the escape hatch.

Fitted recipes

What Recipe.fit() returns: an immutable, fitted pipeline you can apply to new data. Serialization methods are listed under Serialization below.

FittedRecipe

A trained pipeline: applies statistics learned at fit time to new data.

FittedRecipe.transform()

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

FittedRecipe.summary()

The columns the recipe produces, as a tidy data frame.

Lineage

The column-lineage DAG a fitted recipe maintains: per-column provenance and dtype history, plus the queries that back has_source.

Lineage

The record of where every column came from, and what happened to it.

Lineage.removed

Archived nodes of the columns that steps have removed.

Lineage.summary()

The lineage as a tidy data frame.

Lineage.columns_from_source()

Live columns produced by the step with id == step_id.

Lineage.parents()

Immediate parent columns of name (live or archived).

Lineage.ancestors()

All columns name descends from, transitively.

ColumnNode

One column’s lineage record.

Serialization

Save a fitted recipe to a diffable JSON or YAML format and reload it, or strip fit-only artifacts with minimize().

to_dict()

Serialize a FittedRecipe to a diffable, JSON-safe dict.

from_dict()

Reconstruct a FittedRecipe from the dict produced by to_dict.

to_json()

Serialize a FittedRecipe to a diffable JSON string.

from_json()

Reconstruct a FittedRecipe from the JSON produced by to_json.

to_yaml()

Serialize a FittedRecipe to a diffable YAML string.

from_yaml()

Reconstruct a FittedRecipe from the YAML produced by to_yaml.

minimize()

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

FittedRecipe.to_dict()

Serialize to a diffable, JSON-safe dict. See mlfeatures.to_dict for the layout.

FittedRecipe.from_dict()

Reconstruct a fitted recipe from FittedRecipe.to_dict output. See mlfeatures.from_dict.

FittedRecipe.to_json()

Serialize to a diffable JSON string. See mlfeatures.to_json.

FittedRecipe.from_json()

Reconstruct a fitted recipe from FittedRecipe.to_json output. See mlfeatures.from_json.

FittedRecipe.to_yaml()

Serialize to a diffable YAML string. See mlfeatures.to_yaml.

FittedRecipe.from_yaml()

Reconstruct a fitted recipe from FittedRecipe.to_yaml output. See mlfeatures.from_yaml.

FittedRecipe.minimize()

Return a recipe that keeps only what transform() needs. See mlfeatures.minimize.

Interop

Adapters for using recipes inside other ecosystems.

RecipeTransformer

Wrap a Recipe as a scikit-learn transformer.

Types & selectors

Selector DSL and the schema/type vocabulary that steps are written against.

Selectors

Namespace of factory methods for built-in mlfeatures column selectors.

FeaturesSelector

Base class for all mlfeatures-native column selectors.

Selector
ColSchema

Column schema: the names and dtypes a step reports for a column set.

SchemaInfo

Schema-derived context handed to Step.fit().

Roles

Column → set of role names.

Mode

Shape of a step’s input/output relationship.

KeepOriginals

Whether a step’s keep_original_cols is fixed or up to the caller.

KeepOriginals.for_mode()

The policy that a step of mode must follow.

KeepOriginals.fixed_value()

The mandated keep_original_cols, or None if configurable.

Schema

A structural snapshot of the training data used for boundary checks.

Schema.check()

Validate frame against this snapshot.

DataFrame
Frame
ANY_DTYPE
NUMERIC_DTYPES
AcceptedDtypes

Datasets

Example datasets bundled with the package, loaded on access as polars frames (from mlfeatures.data import credit). Used throughout the user guide and the examples.

data

Example datasets bundled with mlfeatures.

Developing

The abstract Step base class and its lifecycle methods, for authoring new steps. Flattened so each method appears on the reference index.

Step

Abstract base class for a feature-engineering step.

Step.fit()

Resolve selectors, estimate and store statistics, return the fitted step.

Step.transform()

Apply stored statistics to new_data. Never re-estimates.

Step.resolve_selection()

Resolve this step’s columns selector to concrete column names.

Step.update_roles()

Update roles to reflect the column changes made by this step.

Step.schema_in()

Schema of the columns this step consumed. Known after fit().

Step.schema_out()

Schema of the columns this step produced. Known after fit().

Step.output_parents()

Map each column this step produces to its parent input column(s).

Step.accepts_dtypes()

Dtypes this step is valid to apply to.

Step.produces_sparse

Whether this step produces sparse output.

Step.produced_columns()

Ordered names of the columns this step adds to the data frame.

Step.keep_original_cols

Whether to retain the source columns alongside any produced columns.

Step.required_pkgs()

Third-party packages required to run this step. Defaults to none.

Step.check_required_pkgs()

Raise if any package this step declares in required_pkgs is missing.

Step.get_params()

The step’s tunable hyperparameters, keyed by constructor argument name.

Step.set_params()

Return a new untrained step with params replaced.

Step.to_state()

Serialize this step’s fields to a diffable, JSON-safe dict.

Step.from_state()

Reconstruct a step from the dict produced by to_state.

Step.minimize()

Return a copy of this step with fit-only artifacts stripped.

RowOp

Row-altering steps.

StepError

A failure raised while fitting or transforming a step.