Skip to content

Inferencer

mllabs.Inferencer

Applies trained processors to new data for inference.

Created by :meth:~mllabs._trainer.Trainer.to_inferencer. Self-contained — no dependency on Experimenter or Trainer at serve time.

Attributes:

Name Type Description
node_specs dict

{name: ProcessorSpec} for every selected Pipeline node and Predictor. Only edges is actually needed at serve time, so the Inferencer carries these rather than a whole Pipeline.

selected_nodes list[str]

Pipeline node names, topologically ordered.

selected_predictors list[str]

Predictor names producing the output.

n_splits int

Number of cross-validation splits.

node_objs dict

{name: [processor_split0, ...]}.

v

Output column filter applied to Predictor outputs.

trainer_spec dict | None

Where this came from — strings and primitives only, so a deployed pickle can say which Trainer and which pipeline version produced it without carrying either.

load(path) classmethod

Load a saved Inferencer from disk.

Parameters:

Name Type Description Default
path str | Path

Directory containing __inferencer.pkl.

required

Returns:

Name Type Description
Inferencer

Restored inferencer.

process(data, agg='mean', nodes=None)

Run inference on new data and aggregate across splits.

Parameters:

Name Type Description Default
data

Input dataset (pandas/polars DataFrame or numpy array).

required
agg str | callable | None

Aggregation strategy across splits. 'mean' (default), 'mode', a callable receiving a list of per-split DataFrames, or None (returns list). Ignored when n_splits == 1.

'mean'
nodes str | list[str] | None

Predictor node(s) to include. None (default) uses all selected heads.

None

Returns:

Type Description

DataFrame | list: Aggregated predictions, or a list of per-split

predictions when agg=None.

save(path)

Serialize the Inferencer to a single file.

Parameters:

Name Type Description Default
path str | Path

Directory to save into. Creates {path}/__inferencer.pkl.

required