coco_pipe.decoding.ensemble =========================== .. py:module:: coco_pipe.decoding.ensemble .. autoapi-nested-parse:: Ensembling and Out-of-Fold Stacking =================================== 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 --------- .. autoapisummary:: coco_pipe.decoding.ensemble.rank_average coco_pipe.decoding.ensemble.stack_oof_predictions Module Contents --------------- .. py:function:: 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. :param scores: Named scores, each indexed by unit ID (one value per unit). Missing values mean the unit was not scored by that set. :type scores: mapping of str to pandas.Series :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``). :rtype: pandas.DataFrame :raises ValueError: If *scores* is empty or a score set repeats a unit. .. py:function:: 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 :class:`~coco_pipe.decoding.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. :param inputs: Named inputs with ``ids`` (unit IDs) and the config of their single model. ``coords["feature_block"]`` gives per-block preprocessing. :type inputs: mapping of str to (DataContainer, ExperimentConfig) :param y: Binary target indexed by unit ID. :type y: pandas.Series :param folds: Outer fold of each unit of *y*, indexed by unit ID (any order). :type folds: pandas.Series :param inner_cv: Inner splits of each outer training set. Defaults to stratified 5-fold. :type inner_cv: CVConfig, optional :param combiner: Classifier with ``predict_proba`` that accepts ``NaN``. Defaults to a shallow :class:`~sklearn.ensemble.HistGradientBoostingClassifier`. :type combiner: sklearn estimator, optional :param n_jobs: Number of (outer fold, input) fits run in parallel. :type n_jobs: int, default=1 :param random_state: Seed of the default inner splits and combiner. :type random_state: int, default=0 :returns: **scores** -- Out-of-fold positive-class probabilities indexed like *y*. :rtype: 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. :raises RuntimeError: If an input fails to fit.