nirs4all.controllers.shared.prediction_aggregator module

PredictionAggregator - Utility class for aggregating predictions from multiple models.

This module provides aggregation strategies for combining predictions within a branch or across models for stacking and merge operations.

Phase 2 Implementation (Stacking Restoration):

Extracted from MergeController to provide shared prediction aggregation logic for both MergeController and MetaModelController.

Aggregation Strategies:
  • SEPARATE: Stack predictions as separate features (n_models features)

  • MEAN: Simple average of predictions (1 feature)

  • WEIGHTED_MEAN: Weighted average by validation score (1 feature)

  • PROBA_MEAN: Average class probabilities for classification (n_classes features)

Example

>>> from nirs4all.controllers.shared import PredictionAggregator
>>> from nirs4all.operators.data.merge import AggregationStrategy
>>> import numpy as np
>>>
>>> predictions = {
...     "PLS": np.array([1.0, 2.0, 3.0]),
...     "RF": np.array([1.1, 1.9, 3.1]),
... }
>>> aggregated = PredictionAggregator.aggregate(
...     predictions=predictions,
...     strategy=AggregationStrategy.MEAN,
... )
>>> print(aggregated.shape)  # (3, 1)