nirs4all.controllers.shared.model_selector module

ModelSelector - Utility class for selecting models based on validation metrics.

This module provides model ranking and selection strategies for stacking and branch merging operations. It handles model selection based on validation metrics with support for various strategies.

Phase 2 Implementation (Stacking Restoration):

Extracted from MergeController to provide shared model selection logic for both MergeController and MetaModelController.

Selection Strategies:
  • ALL: Use all available models

  • BEST: Use single best model by metric

  • TOP_K: Use top K models by metric

  • EXPLICIT: Use explicitly named models

  • REGEX: Use models matching pattern (future)

  • THRESHOLD: Use models above/below metric threshold (future)

Example

>>> from nirs4all.controllers.shared import ModelSelector
>>> from nirs4all.operators.data.merge import BranchPredictionConfig
>>>
>>> selector = ModelSelector(prediction_store, context)
>>> config = BranchPredictionConfig(branch=0, select="best", metric="rmse")
>>> selected = selector.select_models(["PLS", "RF", "XGB"], config, branch_id=0)
>>> print(selected)  # ["PLS"] (assuming PLS has best RMSE)