code: def hierarchical_k_means(
      X,
      n_clusters,
      init="k-means++",
      batch_size=1000,
      n_init=10,
      max_no_improvement=10,
      verbose=0,
      random_state=0,
  ):
      """Use a recursive k-means to cluster X.
  
      First clustering in sqrt(n_clusters) parcels,
      and Kmeans a second time on each parcel.
  
      Parameters
      ----------
      X: ndarray (n_samples, n_features)
          Data to cluster
  
      n_clusters: int,
          The number of clusters to find.
  
      init : {'k-means++', 'random' or an ndarray}, default='k-means++'
          Method for initialization.
          'k-means++' : selects initial cluster centers for k-means
          clustering in a smart way to speed up convergence. See section
          Notes in k_init for more details.
          'random': choose k observations (rows) at random from data for
          the initial centroids.
          If an ndarray is passed, it should be of shape (n_clusters, n_features)
          and gives the initial centers.
  
      batch_size : int, optional, default: 1000
          Size of the mini batches. (Kmeans performed through MiniBatchKMeans)
  
      n_init : int, default=10
          Number of random initializations that are tried.
          In contrast to KMeans, the algorithm is only run once, using the
          best of the ``n_init`` initializations as measured by inertia.
  
      max_no_improvement : int, default: 10
          Control early stopping based on the consecutive number of mini
          batches that does not yield an improvement on the smoothed inertia.
          To disable convergence detection based on inertia, set
          max_no_improvement to None.
  
      random_state : int, RandomState instance or None (default)
          Determines random number generation for centroid initialization and
          random reassignment. Use an int to make the randomness deterministic.
  
      Returns
      -------
      labels : list of ints (len n_features)
          Parcellation of features in clusters
      """
      n_big_clusters = int(np.sqrt(n_clusters))
      mbk = MiniBatchKMeans(
          init=init,
          n_clusters=n_big_clusters,
          batch_size=batch_size,
          n_init=n_init,
          max_no_improvement=max_no_improvement,
          verbose=verbose,
          random_state=random_state,
      ).fit(X)
      coarse_labels = mbk.labels_
      fine_labels = np.zeros_like(coarse_labels)
      q = 0
      counts = np.bincount(coarse_labels)
      exact_clusters = np.asarray(
          [
              n_clusters * counts[i] * 1.0 / X.shape[0]
              for i in range(n_big_clusters)
          ]
      )
  
      adjusted_clusters = _adjust_small_clusters(
          exact_clusters, n_clusters
      )
      for i, n_small_clusters in enumerate(adjusted_clusters):
          mbk = MiniBatchKMeans(
              init=init,
              n_clusters=n_small_clusters,
              batch_size=batch_size,
              random_state=random_state,
              max_no_improvement=max_no_improvement,
              verbose=verbose,
              n_init=n_init,
          ).fit(X[coarse_labels == i])
          fine_labels[coarse_labels == i] = q + mbk.labels_
          q += n_small_clusters
  
      return _remove_empty_labels(fine_labels)
  
file_path: nilearn/nilearn/regions/hierarchical_kmeans_clustering.py
imports: import warnings
  import numpy
  from sklearn.base import BaseEstimator, ClusterMixin, TransformerMixin
  from sklearn.cluster import MiniBatchKMeans
  from sklearn.utils import check_array
  from sklearn.utils.validation import check_is_fitted
label_desc: Use image node_id 3 for calling a global function with example usage: hierarchical_k_means(X, n_clusters, init, batch_size, n_init, max_no_improvement, verbose, random_state) and returns: _remove_empty_labels