docstr: Rich Caruana's ensemble selection method with bagging.
docstr_tok: ["Rich","Caruana","'s","ensemble","selection","method","with","bagging","."]
code: def _bagging(
      self,
      predictions: List[np.ndarray],
      labels: np.ndarray,
      fraction: float = 0.5,
      n_bags: int = 20,
  ) -> np.ndarray:
      """Rich Caruana's ensemble selection method with bagging."""
      raise ValueError(
          "Bagging might not work with class-based interface!"
      )
      n_models = predictions.shape[0]
      bag_size = int(n_models * fraction)
  
      order_of_each_bag = []
      for j in range(n_bags):
          # Bagging a set of models
          indices = sorted(random.sample(range(0, n_models), bag_size))
          bag = predictions[indices, :, :]
          order, _ = self._fit(predictions=bag, labels=labels)
          order_of_each_bag.append(order)
  
      return np.array(
          order_of_each_bag,
          dtype=np.int64,
      )
  
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 7 for calling the EnsembleSelection obj's underlying member method code with example usage: obj._bagging(predictions, labels, fraction, n_bags) and returns: np