code: def augment_rare_classes(X, label, threshold):
      """Use this method when using certain eval_metrics like log_loss, for which no classes may be filtered out.
      This method will augment dataset with additional examples of rare classes.
      """
      class_counts = X[label].value_counts()
      class_counts_invalid = class_counts[class_counts < threshold]
      if len(class_counts_invalid) == 0:
          logger.debug(
              "augment_rare_classes did not need to duplicate any data from rare classes"
          )
          return X
  
      missing_classes = []
      for clss, n_clss in class_counts_invalid.items():
          if n_clss == 0:
              missing_classes.append(clss)
      if missing_classes:
          logger.warning(
              f"WARNING: {len(missing_classes)} classes were found that have 0 training examples, "
              f"and may lead to downstream issues. "
              f"Consider either providing data for these classes or removing them from the class categories. "
              f"These classes will be ignored: {missing_classes}"
          )
          class_counts_invalid = class_counts_invalid[
              ~class_counts_invalid.index.isin(set(missing_classes))
          ]
  
      if len(class_counts_invalid) == 0:
          # This avoids crash when the only invalid classes were those that appeared 0 times
          return X
  
      aug_df = None
      for clss, n_clss in class_counts_invalid.items():
          n_toadd = threshold - n_clss
          clss_df = X.loc[X[label] == clss]
          if aug_df is None:
              aug_df = clss_df[:0].copy()
          duplicate_times = int(np.floor(n_toadd / n_clss))
          remainder = n_toadd % n_clss
          new_df = clss_df.copy()
          new_df = new_df[:remainder]
          while duplicate_times > 0:
              logger.debug(f"Duplicating data from rare class: {clss}")
              duplicate_times -= 1
              new_df = pd.concat([new_df, clss_df], axis=0)
          aug_df = pd.concat([aug_df, new_df], axis=0)
  
      # Ensure new samples generated via augmentation have unique indices
      aug_df = aug_df.reset_index(drop=True)
      aug_df_len = len(aug_df)
      X_index_aug_start = X.index.max() + 1
      aug_index = [X_index_aug_start + i for i in range(aug_df_len)]
      aug_df.index = aug_index
  
      logger.log(
          20,
          f"Duplicated {len(aug_df)} samples from {len(class_counts_invalid)} rare classes in training set because eval_metric requires all classes have at least {threshold} samples.",
      )
  
      X = pd.concat([X, aug_df], axis=0)
      class_counts = X[label].value_counts()
      class_counts_invalid = class_counts[class_counts < threshold]
      class_counts_invalid = class_counts_invalid[
          ~class_counts_invalid.index.isin(set(missing_classes))
      ]
      if len(class_counts_invalid) > 0:
          raise RuntimeError(
              "augment_rare_classes failed to produce enough data from rare classes"
          )
      return X
  
imports: import logging
  import math
  import pickle
  import random
  import sys
  import time
  from typing import Callable, List, Tuple, Union
  import numpy
  import pandas
  import scipy.stats
  from numpy.typing import ArrayLike
  from pandas import DataFrame, Series
  from sklearn.model_selection import LeaveOneGroupOut, RepeatedKFold, RepeatedStratifiedKFold, train_test_split
  from autogluon.common.utils.resource_utils import ResourceManager
  from ..constants import BINARY, LARGE_DATA_THRESHOLD, MULTICLASS, MULTICLASS_UPPER_LIMIT, QUANTILE, REGRESS_THRESHOLD_LARGE_DATA, REGRESS_THRESHOLD_SMALL_DATA, REGRESSION, SOFTCLASS
  from ..metrics import Scorer, accuracy, pinball_loss, root_mean_squared_error
  from .miscs import warning_filter
label_desc: Use image node_id 8 for calling a global function with example usage: augment_rare_classes(X, label, threshold) and returns: X, X, X