code: def recursive_neighbor_agglomeration(
      X, mask_img, n_clusters, n_iter=10, threshold=1e-7, verbose=0
  ):
      """Recursive neighbor agglomeration (:term:`ReNA`).
  
      It performs iteratively the nearest neighbor grouping.
      See :footcite:t:`Hoyos2019`.
  
      Parameters
      ----------
      X : :class:`numpy.ndarray`
          Training data. shape = [n_samples, n_features]
  
      mask_img : Niimg-like object
          Object used for masking the data.
  
      n_clusters : :obj:`int`
          The number of clusters to find.
  
      n_iter : :obj:`int`, default=10
          Number of iterations.
  
      threshold : :obj:`float` in the close interval [0, 1], default=1e-7
          The threshold is set to handle eccentricities.
  
      verbose : :obj:`int`, default=0
          Verbosity level.
  
      Returns
      -------
      n_components : :obj:`int`
          Number of clusters.
  
      labels : :class:`numpy.ndarray`
          Cluster assignation. shape = [n_features]
  
      References
      ----------
      .. footbibliography::
  
      """
      connectivity = _weighted_connectivity_graph(X, mask_img)
  
      # Initialization
      labels = np.arange(connectivity.shape[0])
      n_components = connectivity.shape[0]
  
      for i in range(n_iter):
          connectivity, X, reduced_labels = _nearest_neighbor_grouping(
              X, connectivity, n_clusters, threshold
          )
  
          labels = reduced_labels[labels]
          n_components = connectivity.shape[0]
  
          if verbose > 0:
              print(
                  f"After iteration number {i + 1}, features are "
                  f" grouped into {n_components} clusters"
              )
  
          if n_components <= n_clusters:
              break
  
      return n_components, labels
  
imports: import warnings
  import numpy
  from joblib import Memory
  from nibabel import Nifti1Image
  from scipy.sparse import coo_matrix, csgraph, dia_matrix
  from sklearn.base import BaseEstimator, ClusterMixin, TransformerMixin
  from sklearn.utils import check_array
  from sklearn.utils.validation import check_is_fitted
  from nilearn._utils import fill_doc
  from nilearn.image import get_data
  from nilearn.masking import unmask_from_to_3d_array
label_desc: Use image node_id 8 for calling a global function with example usage: recursive_neighbor_agglomeration(X, mask_img, n_clusters, n_iter, threshold, verbose) and returns: n_components,  labels