predict_model

Note

This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the Habitat Guide and Python API guide (v2.0) for usage.

predict_model(pipeline: TablePipeline, table: FeatureTable) → PredictionResult[source]

Apply one FITTED pipeline to new rows (the inference recipe).

The pipeline’s preprocessing and feature-selection steps replay the state they learned on the training table – the new rows are normalised with the TRAINING statistics and reduced with the TRAINING selection, never refitted. The table needs no outcome column: inference is legitimate on unlabelled rows, and scoring stays with TablePipeline.evaluate().

Parameters:
  • pipeline – A fitted pipeline, e.g. the pipeline of a ModelResult or one reloaded with TablePipeline.load().

  • table – Rows to predict, carrying the feature columns seen at fit time. An outcome column may be present (external-validation tables) but is never read.

Returns:

The per-row predictions, class probabilities when the terminal model is a classifier, and the run manifest.

Raises:

HABITAPIError – If the pipeline is not fitted or the table lacks a feature column seen at fit time.

Examples

>>> from habit.datasets import make_synthetic_feature_table
>>> from habit.spec import MLSpec, Spec
>>> import habit.recipes as recipes
>>> table = make_synthetic_feature_table(n_rows=60, n_features=8, rng=42)
>>> spec = MLSpec(
...     name="demo",
...     steps=(Spec("zscore"),),
...     classifier=Spec("LogisticRegression", {"max_iter": 500}),
...     metrics=(Spec("accuracy"),),
... )
>>> fitted = recipes.train_model(table, spec, seed=42)
>>> prediction = recipes.predict_model(fitted.pipeline, table)
>>> len(prediction.predictions) == len(table.frame)
True