nirs4all.pipeline.predictor module

Pipeline predictor - Handles prediction mode execution.

This module provides the Predictor class for running predictions using trained pipelines on new datasets.

Supports two prediction paths:
  • Bundle path: .n4a bundles loaded via BundleLoader (self-contained).

  • Resolver path: Prediction dicts / folders resolved via PredictionResolver, with optional minimal pipeline extraction from execution traces.

class nirs4all.pipeline.predictor.Predictor(runner: PipelineRunner, use_minimal_pipeline: bool = True)[source]

Bases: object

Handles prediction using trained pipelines.

This class manages the prediction workflow: loading saved models, replaying pipeline configurations, and generating predictions on new data.

When use_minimal_pipeline=True (default), the predictor will: 1. Check if an execution trace is available for the prediction. 2. Extract the minimal pipeline (only required steps) from the trace. 3. Execute only those steps, significantly reducing prediction time.

Variables:
  • runner – Parent PipelineRunner instance.

  • pipeline_uid – Unique identifier for the pipeline.

  • artifact_loader – Loader for trained model artifacts.

  • config_path – Path to the pipeline configuration.

  • target_model – Metadata for the target model.

  • use_minimal_pipeline – Whether to use minimal pipeline execution.

predict(prediction_obj: dict[str, Any] | str, dataset: DatasetConfigs | SpectroDataset | ndarray | tuple[ndarray, ...] | dict | list[dict] | str | list[str], dataset_name: str = 'prediction_dataset', all_predictions: bool = False, verbose: int = 0) → tuple[ndarray, Predictions] | tuple[dict[str, Any], Predictions][source]

Run prediction using a saved model on new dataset.

Parameters:
  • prediction_obj – Model identifier (dict with config_path or prediction ID).

  • dataset – New dataset to predict on.

  • dataset_name – Name for the dataset.

  • all_predictions – If True, return all predictions; if False, return single best.

  • verbose – Verbosity level.

Returns:

(y_pred, predictions) If all_predictions=True: (predictions_dict, predictions)

Return type:

If all_predictions=False