class_docstr: Hierarchical KMeans.
  
  First clusterize the samples into big clusters. Then clusterize the samples
  inside these big clusters into smaller ones.
  
  Parameters
  ----------
  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.
  
  scaling: bool, optional (default False)
      If scaling is True, each cluster is scaled by the square root of its
      size during transform(), preserving the l2-norm of the image.
      inverse_transform() will apply inversed scaling to yield an image with
      same l2-norm as input.
  
  verbose: int, optional (default 0)
      Verbosity level.
  
  Attributes
  ----------
  labels_ : ndarray, shape = [n_features]
      cluster labels for each feature.
  
  sizes_ : ndarray, shape = [n_features]
      It contains the size of each cluster.
class_docstr_tok: ["Hierarchical","KMeans",".","First","clusterize","the","samples","into","big","clusters",".","Then","clusterize","the","samples","inside","these","big","clusters","into","smaller","ones",".","Parameters","--","--","--","--","--","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",".","scaling",":","bool",",","optional","(","default","False",")","If","scaling","is","True",",","each","cluster","is","scaled","by","the","square","root","of","its","size","during","transform","(",")",",","preserving","the","l2-norm","of","the","image",".","inverse_transform","(",")","will","apply","inversed","scaling","to","yield","an","image","with","same","l2-norm","as","input",".","verbose",":","int",",","optional","(","default","0",")","Verbosity","level",".","Attributes","--","--","--","--","--","labels_",":","ndarray",",","shape","=","[","n_features","]","cluster","labels","for","each","feature",".","sizes_",":","ndarray",",","shape","=","[","n_features","]","It","contains","the","size","of","each","cluster","."]
docstr: Compute clustering of the data.
  
  Parameters
  ----------
  X: ndarray, shape = [n_features, n_samples]
      Training data.
  y: Ignored
  
  Returns
  -------
  self
docstr_tok: ["Compute","clustering","of","the","data",".","Parameters","--","--","--","--","--","X",":","ndarray",",","shape","=","[","n_features",",","n_samples","]","Training","data",".","y",":","Ignored","Returns","--","--","--","-","self"]
code: def fit(self, X, y=None):
      """Compute clustering of the data.
  
      Parameters
      ----------
      X: ndarray, shape = [n_features, n_samples]
          Training data.
      y: Ignored
  
      Returns
      -------
      self
      """
      X = check_array(
          X, ensure_min_features=2, ensure_min_samples=2, estimator=self
      )
      n_features = X.shape[1]
  
      if self.n_clusters <= 0:
          raise ValueError(
              "n_clusters should be an integer greater than 0."
              f" {self.n_clusters} was provided."
          )
  
      if self.n_clusters > n_features:
          self.n_clusters = n_features
          warnings.warn(
              "n_clusters should be at most the number of "
              f"features. Taking n_clusters = {n_features} instead."
          )
      self.labels_ = hierarchical_k_means(
          X,
          self.n_clusters,
          self.init,
          self.batch_size,
          self.n_init,
          self.max_no_improvement,
          self.verbose,
          self.random_state,
      )
      sizes = np.bincount(self.labels_)
  
      self.sizes_ = sizes
      self.n_clusters = len(sizes)
      return self
  
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 2 for calling the HierarchicalKMeans obj's underlying member method code with example usage: obj.fit(X, y) and returns: self