docstr: Modify training data, validation data, and model fit kwargs appropriately by subsampling, adding noise columns, replacing bagged
  models, and more.
docstr_tok: ["Modify","training","data",",","validation","data",",","and","model","fit","kwargs","appropriately","by","subsampling",",","adding","noise","columns",",","replacing","bagged","models",",","and","more","."]
code: def setup(
      self,
      X: pd.DataFrame,
      y: pd.DataFrame,
      X_val: pd.DataFrame,
      y_val: pd.DataFrame,
      n_train_subsample: int,
      prune_threshold: float,
      **kwargs: dict,
  ) -> Tuple[
      pd.DataFrame,
      pd.Series,
      pd.DataFrame,
      pd.Series,
      pd.DataFrame,
      pd.Series,
      Union[float, str],
      List[str],
  ]:
      """
      Modify training data, validation data, and model fit kwargs appropriately by subsampling, adding noise columns, replacing bagged
      models, and more.
      """
      # subsample training data
      min_fi_samples = kwargs.get("min_fi_samples", 10000)
      random_state = self.rng.integers(low=0, high=1e5)
      if n_train_subsample is not None and len(X) > n_train_subsample:
          logger.log(
              20,
              f"\tNumber of training samples {len(X)} is greater than {n_train_subsample}. Using {n_train_subsample} samples as training data.",
          )
          drop_ratio = 1.0 - n_train_subsample / len(X)
          X_train, _, y_train, _ = generate_train_test_split(
              X=X,
              y=y,
              problem_type=self.problem_type,
              random_state=random_state,
              test_size=drop_ratio,
          )
      else:
          X_train, y_train = X, y
  
      # replace bagged model with its child model for the proxy model if replace_bag=True (overrides subsampling if triggered)
      if n_train_subsample is None:
          trigger_replace_bag = (
              kwargs.get("replace_bag", False) and self.is_bagged
          )
      else:
          trigger_replace_bag = (
              kwargs.get("replace_bag", True)
              and self.is_bagged
              and len(X) > n_train_subsample + min_fi_samples
          )
      if trigger_replace_bag:
          logger.log(
              20,
              f"\tFeature selection model is bagged and replace_bag=True. Using a non-bagged version of the model for feature selection.",
          )
          val_ratio = (
              1.0 - n_train_subsample / len(X)
              if n_train_subsample is not None
              else 0.25
          )
          X_train, X_val, y_train, y_val = generate_train_test_split(
              X=X,
              y=y,
              problem_type=self.problem_type,
              random_state=random_state,
              test_size=val_ratio,
          )
          self.is_bagged = False
          self.replace_bag = True
  
      # Be more lenient with feature importance computation shuffles for very high dimensional datasets for time's sake
      if len(X_train.columns) > 1000:
          self.max_n_shuffle = self.max_n_shuffle // 2
  
      # set prune_threshold and optionally modify feature_metadata
      noise_columns = []
      feature_metadata = deepcopy(kwargs.get("feature_metadata", None))
      if prune_threshold == "none":
          prune_threshold = float("inf")
      elif prune_threshold == "noise":
          X_train, noise_columns = add_noise_column(
              X=X_train, rng=self.rng
          )
          if feature_metadata is not None:
              for noise_column in noise_columns:
                  feature_metadata.type_map_raw[noise_column] = R_FLOAT
          if isinstance(X_val, pd.DataFrame):
              X_val, _ = add_noise_column(
                  X=X_val, rng=self.rng, noise_columns=noise_columns
              )
      else:
          assert isinstance(
              prune_threshold, float
          ), "prune_threshold must be float, 'noise', or 'none'."
      X_fi, y_fi = (
          (X_train, y_train) if self.is_bagged else (X_val, y_val)
      )
      return (
          X_train,
          y_train,
          X_val,
          y_val,
          X_fi,
          y_fi,
          prune_threshold,
          noise_columns,
          feature_metadata,
      )
  
imports: import logging
  import time
  import traceback
  import uuid
  from copy import deepcopy
  from typing import List, Set, Tuple, Union
  import numpy
  import pandas
  from autogluon.common.features.types import R_FLOAT
  from ..models.abstract.abstract_model import AbstractModel
  from ..models.ensemble.bagged_ensemble_model import BaggedEnsembleModel
  from ..utils.exceptions import TimeLimitExceeded
  from ..utils.utils import generate_train_test_split, unevaluated_fi_df_template
label_desc: Use image node_id 10 for calling the FeatureSelector obj's underlying member method code with example usage: obj.setup(X, y, X_val, y_val, n_train_subsample, prune_threshold) and returns: X_train,  y_train,  X_val,  y_val,  X_fi,  y_fi,  prune_threshold,  noise_columns,  feature_metadata