coco_pipe.decoding.ensemble#

Combine out-of-fold scores of several decoders over units that each decoder may only partly cover, without imputing the units a decoder did not score.

Functions#

rank_average(scores)

Average percentile ranks per unit over score sets with partial overlap.

stack_oof_predictions(inputs, y, folds, *[, inner_cv, ...])

Nested out-of-fold stacking over inputs that cover different units.

Module Contents#

coco_pipe.decoding.ensemble.rank_average(scores)#

Average percentile ranks per unit over score sets with partial overlap.

Each score set is ranked on its own, so sets with different calibrations weigh the same. A unit’s score is the mean of its ranks over the sets that scored it.

Parameters:

scores (mapping of str to pandas.Series) – Named scores, each indexed by unit ID (one value per unit). Missing values mean the unit was not scored by that set.

Returns:

ranks – Indexed by unit ID, with the mean rank in (0, 1] (score) and the number of sets that scored the unit (n_fits).

Return type:

pandas.DataFrame

Raises:

ValueError – If scores is empty or a score set repeats a unit.

coco_pipe.decoding.ensemble.stack_oof_predictions(inputs, y, folds, *, inner_cv=None, combiner=None, n_jobs=1, random_state=0)#

Nested out-of-fold stacking over inputs that cover different units.

For each outer fold, every input scores the training units it covers by an inner cross-validation and the test units it covers by a model fit on all of its training units (each through Experiment). The combiner learns from the inner scores and scores the test units. A unit an input does not cover stays NaN (no imputation), so the combiner must accept missing values.

Parameters:
  • inputs (mapping of str to (DataContainer, ExperimentConfig)) – Named inputs with ids (unit IDs) and the config of their single model. coords["feature_block"] gives per-block preprocessing.

  • y (pandas.Series) – Binary target indexed by unit ID.

  • folds (pandas.Series) – Outer fold of each unit of y, indexed by unit ID (any order).

  • inner_cv (CVConfig, optional) – Inner splits of each outer training set. Defaults to stratified 5-fold.

  • combiner (sklearn estimator, optional) – Classifier with predict_proba that accepts NaN. Defaults to a shallow HistGradientBoostingClassifier.

  • n_jobs (int, default=1) – Number of (outer fold, input) fits run in parallel.

  • random_state (int, default=0) – Seed of the default inner splits and combiner.

Returns:

scores – Out-of-fold positive-class probabilities indexed like y.

Return type:

pandas.Series

Raises:
  • ValueError – If inputs is empty, a unit of y has no fold, an input has no ids, its ids share no unit with y, or its config holds more than one model.

  • RuntimeError – If an input fails to fit.