class_docstr: k-modes clustering algorithm for categorical data.
  
  Parameters
  -----------
  n_clusters : int, optional, default: 8
      The number of clusters to form as well as the number of
      centroids to generate.
  
  max_iter : int, default: 100
      Maximum number of iterations of the k-modes algorithm for a
      single run.
  
  cat_dissim : func, default: matching_dissim
      Dissimilarity function used by the k-modes algorithm for categorical variables.
      Defaults to the matching dissimilarity function.
  
  init : {'Huang', 'Cao', 'random' or an ndarray}, default: 'Cao'
      Method for initialization:
      'Huang': Method in Huang [1997, 1998]
      'Cao': Method in Cao et al. [2009]
      'random': choose 'n_clusters' observations (rows) at random from
      data for the initial centroids.
      If an ndarray is passed, it should be of shape (n_clusters, n_features)
      for the initial encoded centroids.
  
  n_init : int, default: 10
      Number of time the k-modes algorithm will be run with different
      centroid seeds. The final results will be the best output of
      n_init consecutive runs in terms of cost.
  
  verbose : int, optional
      Verbosity mode.
  
  random_state : int, RandomState instance or None, optional, default: None
      If int, random_state is the seed used by the random number generator;
      If RandomState instance, random_state is the random number generator;
      If None, the random number generator is the RandomState instance used
      by `np.random`.
  
  n_jobs : int, default: 1
      The number of jobs to use for the computation. This works by computing
      each of the n_init runs in parallel.
      If -1 all CPUs are used. If 1 is given, no parallel computing code is
      used at all, which is useful for debugging. For n_jobs below -1,
      (n_cpus + 1 + n_jobs) are used. Thus for n_jobs = -2, all CPUs but one
      are used.
  
  Attributes
  ----------
  cluster_centroids_ : array, [n_clusters, n_features]
      Categories of cluster centroids
  
  labels_ :
      Labels of each point
  
  cost_ : float
      Clustering cost, defined as the sum distance of all points to
      their respective cluster centroids.
  
  n_iter_ : int
      The number of iterations the algorithm ran for.
  
  epoch_costs_ :
      The cost of the algorithm at each epoch from start to completion.
  
  Notes
  -----
  See:
  Huang, Z.: Extensions to the k-modes algorithm for clustering large
  data sets with categorical values, Data Mining and Knowledge
  Discovery 2(3), 1998.
class_docstr_tok: ["k-modes","clustering","algorithm","for","categorical","data",".","Parameters","--","--","--","--","--","-","n_clusters",":","int",",","optional",",","default",":","8","The","number","of","clusters","to","form","as","well","as","the","number","of","centroids","to","generate",".","max_iter",":","int",",","default",":","100","Maximum","number","of","iterations","of","the","k-modes","algorithm","for","a","single","run",".","cat_dissim",":","func",",","default",":","matching_dissim","Dissimilarity","function","used","by","the","k-modes","algorithm","for","categorical","variables",".","Defaults","to","the","matching","dissimilarity","function",".","init",":","{","'Huang","'",",","'Cao","'",",","'random","'","or","an","ndarray","}",",","default",":","'Cao'","Method","for","initialization",":","'Huang","'",":","Method","in","Huang","[","1997",",","1998","]","'Cao","'",":","Method","in","Cao","et","al",".","[","2009","]","'random","'",":","choose","'n_clusters","'","observations","(","rows",")","at","random","from","data","for","the","initial","centroids",".","If","an","ndarray","is","passed",",","it","should","be","of","shape","(","n_clusters",",","n_features",")","for","the","initial","encoded","centroids",".","n_init",":","int",",","default",":","10","Number","of","time","the","k-modes","algorithm","will","be","run","with","different","centroid","seeds",".","The","final","results","will","be","the","best","output","of","n_init","consecutive","runs","in","terms","of","cost",".","verbose",":","int",",","optional","Verbosity","mode",".","random_state",":","int",",","RandomState","instance","or","None",",","optional",",","default",":","None","If","int",",","random_state","is","the","seed","used","by","the","random","number","generator",";","If","RandomState","instance",",","random_state","is","the","random","number","generator",";","If","None",",","the","random","number","generator","is","the","RandomState","instance","used","by","`","np.random","`",".","n_jobs",":","int",",","default",":","1","The","number","of","jobs","to","use","for","the","computation",".","This","works","by","computing","each","of","the","n_init","runs","in","parallel",".","If","-1","all","CPUs","are","used",".","If","1","is","given",",","no","parallel","computing","code","is","used","at","all",",","which","is","useful","for","debugging",".","For","n_jobs","below","-1",",","(","n_cpus","+","1","+","n_jobs",")","are","used",".","Thus","for","n_jobs","=","-2",",","all","CPUs","but","one","are","used",".","Attributes","--","--","--","--","--","cluster_centroids_",":","array",",","[","n_clusters",",","n_features","]","Categories","of","cluster","centroids","labels_",":","Labels","of","each","point","cost_",":","float","Clustering","cost",",","defined","as","the","sum","distance","of","all","points","to","their","respective","cluster","centroids",".","n_iter_",":","int","The","number","of","iterations","the","algorithm","ran","for",".","epoch_costs_",":","The","cost","of","the","algorithm","at","each","epoch","from","start","to","completion",".","Notes","--","--","-","See",":","Huang",",","Z.",":","Extensions","to","the","k-modes","algorithm","for","clustering","large","data","sets","with","categorical","values",",","Data","Mining","and","Knowledge","Discovery","2","(","3",")",",","1998","."]
docstr: Compute cluster centroids and predict cluster index for each sample.
  
  Convenience method; equivalent to calling fit(X) followed by
  predict(X).
docstr_tok: ["Compute","cluster","centroids","and","predict","cluster","index","for","each","sample",".","Convenience","method",";","equivalent","to","calling","fit","(","X",")","followed","by","predict","(","X",")","."]
code: def fit_predict(self, X, y=None, **kwargs):
      """Compute cluster centroids and predict cluster index for each sample.
  
      Convenience method; equivalent to calling fit(X) followed by
      predict(X).
      """
      return self.fit(X, **kwargs).predict(X, **kwargs)
  
imports: from collections import defaultdict
  import numpy
  from joblib import Parallel, delayed
  from scipy import sparse
  from sklearn.base import BaseEstimator, ClusterMixin
  from sklearn.utils import check_random_state
  from sklearn.utils.validation import check_array
  from .util import get_max_value_key, encode_features, get_unique_rows, decode_centroids, pandas_to_numpy
  from .util.dissim import matching_dissim, ng_dissim
  from .util.init_methods import init_cao, init_huang
label_desc: Use image node_id 3 for calling the KModes obj's underlying member method code with example usage: obj.fit_predict(X, y) and returns: self