code: def cluster(self, n, embed_dim=None, algo=spectral.SPECTRAL, method=methods.KMEANS):
          
          if n == 1:
              return Partition([1] * len(self.get_dm(False)))
  
          if embed_dim is None:
              embed_dim = n
  
          if algo == spectral.SPECTRAL:
              self._coords = self.spectral_embedding(embed_dim)
          elif algo == spectral.KPCA:
              self._coords = self.kpca_embedding(embed_dim)
          elif algo == spectral.ZELNIKMANOR:
              self._coords = self.spectral_embedding_(embed_dim)
          else:
              raise OptionError(algo, list(spectral.reverse.values()))
          if method == methods.KMEANS:
              p = self.kmeans(n, self._coords.df.values)
          elif method == methods.GMM:
              p = self.gmm(n, self._coords.df.values)
          elif method == methods.WARD:
              linkmat = fastcluster.linkage(self._coords.values, 'ward')
              p = _hclust(linkmat, n)
          else:
              raise OptionError(method, list(methods.reverse.values()))
          if self._verbosity > 0:
              print('Using clustering method: {}'.format(methods.reverse[method]))
          return p
docs: Cluster the embedded coordinates using spectral clustering
  
          Parameters
          ----------
          n:                 int
                             The number of clusters to return
          embed_dim:         int
                             The dimensionality of the underlying coordinates
                             Defaults to same value as n
          algo:              enum value (spectral.SPECTRAL | spectral.KPCA | spectral.ZELNIKMANOR)
                             Type of embedding to use
          method:            enum value (methods.KMEANS | methods.GMM)
                             The clustering method to use
  
          Returns
          -------
          Partition: Partition object describing the data partition