code: def _approximate_mode(class_counts, n_draws, rng):
      """Computes approximate mode of multivariate hypergeometric.
  
      This is an approximation to the mode of the multivariate
      hypergeometric given by class_counts and n_draws.
      It shouldn't be off by more than one.
  
      It is the mostly likely outcome of drawing n_draws many
      samples from the population given by class_counts.
  
      Parameters
      ----------
      class_counts : ndarray of int
          Population per class.
      n_draws : int
          Number of draws (samples to draw) from the overall population.
      rng : random state
          Used to break ties.
  
      Returns
      -------
      sampled_classes : ndarray of int
          Number of samples drawn from each class.
          np.sum(sampled_classes) == n_draws
  
      Examples
      --------
      >>> import numpy as np
      >>> from sklearn.utils import _approximate_mode
      >>> _approximate_mode(class_counts=np.array([4, 2]), n_draws=3, rng=0)
      array([2, 1])
      >>> _approximate_mode(class_counts=np.array([5, 2]), n_draws=4, rng=0)
      array([3, 1])
      >>> _approximate_mode(class_counts=np.array([2, 2, 2, 1]),
      ...                   n_draws=2, rng=0)
      array([0, 1, 1, 0])
      >>> _approximate_mode(class_counts=np.array([2, 2, 2, 1]),
      ...                   n_draws=2, rng=42)
      array([1, 1, 0, 0])
      """
      rng = check_random_state(rng)
      # this computes a bad approximation to the mode of the
      # multivariate hypergeometric given by class_counts and n_draws
      continuous = class_counts / class_counts.sum() * n_draws
      # floored means we don't overshoot n_samples, but probably undershoot
      floored = np.floor(continuous)
      # we add samples according to how much "left over" probability
      # they had, until we arrive at n_samples
      need_to_add = int(n_draws - floored.sum())
      if need_to_add > 0:
          remainder = continuous - floored
          values = np.sort(np.unique(remainder))[::-1]
          # add according to remainder, but break ties
          # randomly to avoid biases
          for value in values:
              (inds,) = np.where(remainder == value)
              # if we need_to_add less than what's in inds
              # we draw randomly from them.
              # if we need to add more, we add them all and
              # go to the next value
              add_now = min(len(inds), need_to_add)
              inds = rng.choice(inds, size=add_now, replace=False)
              floored[inds] += 1
              need_to_add -= add_now
              if need_to_add == 0:
                  break
      return floored.astype(int)
  
imports: import math
  import numbers
  import platform
  import struct
  import timeit
  import warnings
  from collections.abc import Sequence
  from contextlib import contextmanager, suppress
  from itertools import compress, islice
  import numpy
  from scipy.sparse import issparse
  from ..None import get_config
  from ..exceptions import DataConversionWarning
  from .None import _joblib, metadata_routing
  from ._bunch import Bunch
  from ._estimator_html_repr import estimator_html_repr
  from ._param_validation import Interval, validate_params
  from .class_weight import compute_class_weight, compute_sample_weight
  from .deprecation import deprecated
  from .discovery import all_estimators
  from .fixes import parse_version, threadpool_info
  from .murmurhash import murmurhash3_32
  from .validation import _is_arraylike_not_scalar, as_float_array, assert_all_finite, check_array, check_consistent_length, check_random_state, check_scalar, check_symmetric, check_X_y, column_or_1d, indexable
label_desc: Use image node_id 25 for calling a global function with example usage: _approximate_mode(class_counts, n_draws, rng) and returns: floored