docstr: An ensemble of selected algorithms
  
  Fitting an EnsembleSelection generates an ensemble from the the models
  generated during the search process. Can be further used for prediction.
  
  Parameters
  ----------
  task_type: int
      An identifier indicating which task is being performed.
  
  metrics: Sequence[Scorer] | Scorer
      The metric used to evaluate the models. If multiple metrics are passed,
      ensemble selection only optimizes for the first
  
  backend : Backend
      Gives access to the backend of Auto-sklearn. Not used by Ensemble Selection.
  
  bagging: bool = False
      Whether to use bagging in ensemble selection
  
  mode: str in ['fast', 'slow'] = 'fast'
      Which kind of ensemble generation to use
      * 'slow' - The original method used in Rich Caruana's ensemble selection.
      * 'fast' - A faster version of Rich Caruanas' ensemble selection.
  
  random_state: int | RandomState | None = None
      The random_state used for ensemble selection.
  
      * None - Uses numpy's default RandomState object
      * int - Successive calls to fit will produce the same results
      * RandomState - Truly random, each call to fit will produce
        different results, even with the same object.
  
  References
  ----------
  | Ensemble selection from libraries of models
  | Rich Caruana, Alexandru Niculescu-Mizil, Geoff Crew and Alex Ksikes
  | ICML 2004
  | https://dl.acm.org/doi/10.1145/1015330.1015432
  | https://www.cs.cornell.edu/~caruana/ctp/ct.papers/caruana.icml04.icdm06long.pdf
docstr_tok: ["An","ensemble","of","selected","algorithms","Fitting","an","EnsembleSelection","generates","an","ensemble","from","the","the","models","generated","during","the","search","process",".","Can","be","further","used","for","prediction",".","Parameters","--","--","--","--","--","task_type",":","int","An","identifier","indicating","which","task","is","being","performed",".","metrics",":","Sequence","[","Scorer","]","|","Scorer","The","metric","used","to","evaluate","the","models",".","If","multiple","metrics","are","passed",",","ensemble","selection","only","optimizes","for","the","first","backend",":","Backend","Gives","access","to","the","backend","of","Auto-sklearn",".","Not","used","by","Ensemble","Selection",".","bagging",":","bool","=","False","Whether","to","use","bagging","in","ensemble","selection","mode",":","str","in","[","'fast","'",",","'slow","'","]","=","'fast'","Which","kind","of","ensemble","generation","to","use","*","'slow","'","-","The","original","method","used","in","Rich","Caruana","'s","ensemble","selection",".","*","'fast","'","-","A","faster","version","of","Rich","Caruanas","'","ensemble","selection",".","random_state",":","int","|","RandomState","|","None","=","None","The","random_state","used","for","ensemble","selection",".","*","None","-","Uses","numpy","'s","default","RandomState","object","*","int","-","Successive","calls","to","fit","will","produce","the","same","results","*","RandomState","-","Truly","random",",","each","call","to","fit","will","produce","different","results",",","even","with","the","same","object",".","References","--","--","--","--","--","|","Ensemble","selection","from","libraries","of","models","|","Rich","Caruana",",","Alexandru","Niculescu-Mizil",",","Geoff","Crew","and","Alex","Ksikes","|","ICML","2004","|","https",":","\/\/dl.acm.org\/doi\/10.1145\/1015330.1015432","|","https",":","\/\/www.cs.cornell.edu\/~caruana\/ctp\/ct.papers\/caruana.icml04.icdm06long.pdf"]
code: def __init__(
      self,
      task_type: int,
      metrics: Sequence[Scorer] | Scorer,
      backend: Backend,
      ensemble_size: int = 50,
      bagging: bool = False,
      mode: str = "fast",
      random_state: int | np.random.RandomState | None = None,
  ) -> None:
      """An ensemble of selected algorithms
  
      Fitting an EnsembleSelection generates an ensemble from the the models
      generated during the search process. Can be further used for prediction.
  
      Parameters
      ----------
      task_type: int
          An identifier indicating which task is being performed.
  
      metrics: Sequence[Scorer] | Scorer
          The metric used to evaluate the models. If multiple metrics are passed,
          ensemble selection only optimizes for the first
  
      backend : Backend
          Gives access to the backend of Auto-sklearn. Not used by Ensemble Selection.
  
      bagging: bool = False
          Whether to use bagging in ensemble selection
  
      mode: str in ['fast', 'slow'] = 'fast'
          Which kind of ensemble generation to use
          * 'slow' - The original method used in Rich Caruana's ensemble selection.
          * 'fast' - A faster version of Rich Caruanas' ensemble selection.
  
      random_state: int | RandomState | None = None
          The random_state used for ensemble selection.
  
          * None - Uses numpy's default RandomState object
          * int - Successive calls to fit will produce the same results
          * RandomState - Truly random, each call to fit will produce
            different results, even with the same object.
  
      References
      ----------
      | Ensemble selection from libraries of models
      | Rich Caruana, Alexandru Niculescu-Mizil, Geoff Crew and Alex Ksikes
      | ICML 2004
      | https://dl.acm.org/doi/10.1145/1015330.1015432
      | https://www.cs.cornell.edu/~caruana/ctp/ct.papers/caruana.icml04.icdm06long.pdf
      """  # noqa: E501
      self.ensemble_size = ensemble_size
      self.task_type = task_type
      if isinstance(metrics, Sequence):
          if len(metrics) > 1:
              warnings.warn(
                  "Ensemble selection can only optimize one metric, "
                  "but multiple metrics were passed, dropping all "
                  "except for the first metric."
              )
          self.metric = metrics[0]
      else:
          self.metric = metrics
      self.bagging = bagging
      self.mode = mode
  
      # Behaviour similar to sklearn
      #   int - Deteriministic with succesive calls to fit
      #   RandomState - Successive calls to fit will produce differences
      #   None - Uses numpmys global singleton RandomState
      # https://scikit-learn.org/stable/common_pitfalls.html#controlling-randomness
      self.random_state = random_state
  
imports: from __future__ import annotations
  from typing import Dict, List, Sequence, Tuple, Union
  import random
  import warnings
  from collections import Counter
  import numpy
  from sklearn.utils import check_random_state
  from autosklearn.automl_common.common.utils.backend import Backend
  from autosklearn.constants import TASK_TYPES
  from autosklearn.data.validation import SUPPORTED_FEAT_TYPES
  from autosklearn.ensemble_building.run import Run
  from autosklearn.ensembles.abstract_ensemble import AbstractEnsemble
  from autosklearn.metrics import Scorer, calculate_losses
  from autosklearn.pipeline.base import BasePipeline
label_desc: Use image node_id 1 to create a new EnsembleSelection object from inherited base classes: AbstractEnsemble with example: obj = EnsembleSelection(task_type, metrics, backend, ensemble_size, bagging, mode, random_state)