code: def test_balanced_bagging_classifier_with_function_sampler(replace):
      # check that we can provide a FunctionSampler in BalancedBaggingClassifier
      X, y = make_classification(
          n_samples=1_000,
          n_features=10,
          n_classes=2,
          weights=[0.3, 0.7],
          random_state=0,
      )
  
      def roughly_balanced_bagging(X, y, replace=False):
          """Implementation of Roughly Balanced Bagging for binary problem."""
          # find the minority and majority classes
          class_counts = Counter(y)
          majority_class = max(class_counts, key=class_counts.get)
          minority_class = min(class_counts, key=class_counts.get)
  
          # compute the number of sample to draw from the majority class using
          # a negative binomial distribution
          n_minority_class = class_counts[minority_class]
          n_majority_resampled = np.random.negative_binomial(
              n=n_minority_class, p=0.5
          )
  
          # draw randomly with or without replacement
          majority_indices = np.random.choice(
              np.flatnonzero(y == majority_class),
              size=n_majority_resampled,
              replace=replace,
          )
          minority_indices = np.random.choice(
              np.flatnonzero(y == minority_class),
              size=n_minority_class,
              replace=replace,
          )
          indices = np.hstack([majority_indices, minority_indices])
  
          return X[indices], y[indices]
  
      # Roughly Balanced Bagging
      rbb = BalancedBaggingClassifier(
          estimator=CountDecisionTreeClassifier(random_state=0),
          n_estimators=2,
          sampler=FunctionSampler(
              func=roughly_balanced_bagging,
              kw_args={"replace": replace},
          ),
          random_state=0,
      )
      rbb.fit(X, y)
  
      for estimator in rbb.estimators_:
          class_counts = estimator[-1].class_counts_
          assert (class_counts[0] / class_counts[1]) > 0.78
  
imports: from collections import Counter
  import numpy
  import pytest
  import sklearn
  from sklearn.cluster import KMeans
  from sklearn.datasets import load_iris, make_classification, make_hastie_10_2
  from sklearn.dummy import DummyClassifier
  from sklearn.feature_selection import SelectKBest
  from sklearn.linear_model import LogisticRegression, Perceptron
  from sklearn.model_selection import GridSearchCV, ParameterGrid, train_test_split
  from sklearn.neighbors import KNeighborsClassifier
  from sklearn.svm import SVC
  from sklearn.tree import DecisionTreeClassifier
  from sklearn.utils._testing import assert_allclose, assert_array_almost_equal, assert_array_equal
  from sklearn.utils.fixes import parse_version
  from imblearn import FunctionSampler
  from imblearn.datasets import make_imbalance
  from imblearn.ensemble import BalancedBaggingClassifier
  from imblearn.over_sampling import SMOTE, RandomOverSampler
  from imblearn.pipeline import make_pipeline
  from imblearn.under_sampling import ClusterCentroids, RandomUnderSampler
label_desc: Use image node_id 20 for calling a global function with example usage: test_balanced_bagging_classifier_with_function_sampler(replace) and returns: X,  y