class_docstr: Kernel K-means.
  
  Parameters
  ----------
  n_clusters : int (default: 3)
      Number of clusters to form.
  
  kernel : string, or callable (default: "gak")
      The kernel should either be "gak", in which case the Global Alignment
      Kernel from [2]_ is used or a value that is accepted as a metric
      by `scikit-learn's pairwise_kernels
      <https://scikit-learn.org/stable/modules/generated/        sklearn.metrics.pairwise.pairwise_kernels.html>`_
  
  max_iter : int (default: 50)
      Maximum number of iterations of the k-means algorithm for a single run.
  
  tol : float (default: 1e-6)
      Inertia variation threshold. If at some point, inertia varies less than
      this threshold between two consecutive
      iterations, the model is considered to have converged and the algorithm
      stops.
  
  n_init : int (default: 1)
      Number of time the k-means algorithm will be run with different
      centroid seeds. The final results will be the
      best output of n_init consecutive runs in terms of inertia.
  
  kernel_params : dict or None (default: None)
      Kernel parameters to be passed to the kernel function.
      None means no kernel parameter is set.
      For Global Alignment Kernel, the only parameter of interest is `sigma`.
      If set to 'auto', it is computed based on a sampling of the training
      set
      (cf :ref:`tslearn.metrics.sigma_gak <fun-tslearn.metrics.sigma_gak>`).
      If no specific value is set for `sigma`, its defaults to 1.
  
  n_jobs : int or None, optional (default=None)
      The number of jobs to run in parallel for GAK cross-similarity matrix
      computations.
      ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
      ``-1`` means using all processors. See scikit-learns'
      `Glossary <https://scikit-learn.org/stable/glossary.html#term-n-jobs>`_
      for more details.
  
  verbose : int (default: 0)
      If nonzero, joblib progress messages are printed.
  
  random_state : integer or numpy.RandomState, optional
      Generator used to initialize the centers. If an integer is given, it
      fixes the seed. Defaults to the global
      numpy random number generator.
  
  Attributes
  ----------
  labels_ : numpy.ndarray
      Labels of each point
  
  inertia_ : float
      Sum of distances of samples to their closest cluster center (computed
      using the kernel trick).
  
  sample_weight_ : numpy.ndarray
      The weight given to each sample from the data provided to fit.
  
  n_iter_ : int
      The number of iterations performed during fit.
  
  Notes
  -----
      The training data are saved to disk if this model is
      serialized and may result in a large model file if the training
      dataset is large.
  
  Examples
  --------
  >>> from tslearn.generators import random_walks
  >>> X = random_walks(n_ts=50, sz=32, d=1)
  >>> gak_km = KernelKMeans(n_clusters=3, kernel="gak", random_state=0)
  >>> gak_km.fit(X)  # doctest: +ELLIPSIS
  KernelKMeans(...)
  >>> print(numpy.unique(gak_km.labels_))
  [0 1 2]
  
  References
  ----------
  .. [1] Kernel k-means, Spectral Clustering and Normalized Cuts.
         Inderjit S. Dhillon, Yuqiang Guan, Brian Kulis. KDD 2004.
  
  .. [2] Fast Global Alignment Kernels. Marco Cuturi. ICML 2011.
class_docstr_tok: ["Kernel","K-means",".","Parameters","--","--","--","--","--","n_clusters",":","int","(","default",":","3",")","Number","of","clusters","to","form",".","kernel",":","string",",","or","callable","(","default",":","``","gak","''",")","The","kernel","should","either","be","``","gak","''",",","in","which","case","the","Global","Alignment","Kernel","from","[","2","]","_","is","used","or","a","value","that","is","accepted","as","a","metric","by","`","scikit-learn","'s","pairwise_kernels","<","https",":","\/\/scikit-learn.org\/stable\/modules\/generated\/","sklearn.metrics.pairwise.pairwise_kernels.html",">","`","_","max_iter",":","int","(","default",":","50",")","Maximum","number","of","iterations","of","the","k-means","algorithm","for","a","single","run",".","tol",":","float","(","default",":","1e-6",")","Inertia","variation","threshold",".","If","at","some","point",",","inertia","varies","less","than","this","threshold","between","two","consecutive","iterations",",","the","model","is","considered","to","have","converged","and","the","algorithm","stops",".","n_init",":","int","(","default",":","1",")","Number","of","time","the","k-means","algorithm","will","be","run","with","different","centroid","seeds",".","The","final","results","will","be","the","best","output","of","n_init","consecutive","runs","in","terms","of","inertia",".","kernel_params",":","dict","or","None","(","default",":","None",")","Kernel","parameters","to","be","passed","to","the","kernel","function",".","None","means","no","kernel","parameter","is","set",".","For","Global","Alignment","Kernel",",","the","only","parameter","of","interest","is","`","sigma","`",".","If","set","to","'auto","'",",","it","is","computed","based","on","a","sampling","of","the","training","set","(","cf",":","ref",":","`","tslearn.metrics.sigma_gak","<","fun-tslearn.metrics.sigma_gak",">","`",")",".","If","no","specific","value","is","set","for","`","sigma","`",",","its","defaults","to","1.","n_jobs",":","int","or","None",",","optional","(","default=None",")","The","number","of","jobs","to","run","in","parallel","for","GAK","cross-similarity","matrix","computations",".","``","None","``","means","1","unless","in","a",":","obj",":","`","joblib.parallel_backend","`","context",".","``","-1","``","means","using","all","processors",".","See","scikit-learns'","`","Glossary","<","https",":","\/\/scikit-learn.org\/stable\/glossary.html","#","term-n-jobs",">","`","_","for","more","details",".","verbose",":","int","(","default",":","0",")","If","nonzero",",","joblib","progress","messages","are","printed",".","random_state",":","integer","or","numpy.RandomState",",","optional","Generator","used","to","initialize","the","centers",".","If","an","integer","is","given",",","it","fixes","the","seed",".","Defaults","to","the","global","numpy","random","number","generator",".","Attributes","--","--","--","--","--","labels_",":","numpy.ndarray","Labels","of","each","point","inertia_",":","float","Sum","of","distances","of","samples","to","their","closest","cluster","center","(","computed","using","the","kernel","trick",")",".","sample_weight_",":","numpy.ndarray","The","weight","given","to","each","sample","from","the","data","provided","to","fit",".","n_iter_",":","int","The","number","of","iterations","performed","during","fit",".","Notes","--","--","-","The","training","data","are","saved","to","disk","if","this","model","is","serialized","and","may","result","in","a","large","model","file","if","the","training","dataset","is","large",".","Examples","--","--","--","--",">",">",">","from","tslearn.generators","import","random_walks",">",">",">","X","=","random_walks","(","n_ts=50",",","sz=32",",","d=1",")",">",">",">","gak_km","=","KernelKMeans","(","n_clusters=3",",","kernel=","''","gak","''",",","random_state=0",")",">",">",">","gak_km.fit","(","X",")","#","doctest",":","+ELLIPSIS","KernelKMeans","(","...",")",">",">",">","print","(","numpy.unique","(","gak_km.labels_",")",")","[","0","1","2","]","References","--","--","--","--","--","..","[","1","]","Kernel","k-means",",","Spectral","Clustering","and","Normalized","Cuts",".","Inderjit","S.","Dhillon",",","Yuqiang","Guan",",","Brian","Kulis",".","KDD","2004",".","..","[","2","]","Fast","Global","Alignment","Kernels",".","Marco","Cuturi",".","ICML","2011","."]
code: def _compute_inertia(dist_sq):
      return dist_sq.min(axis=1).sum()
  
imports: import warnings
  import numpy
  import sklearn
  from scipy.spatial.distance import cdist
  from sklearn.base import ClusterMixin, TransformerMixin
  from sklearn.metrics.pairwise import pairwise_kernels
  from sklearn.utils import check_random_state
  from sklearn.utils.extmath import stable_cumsum
  from sklearn.utils.validation import _check_sample_weight
  from sklearn.utils import check_array
  from sklearn.utils.validation import check_is_fitted
  from tslearn.barycenters import dtw_barycenter_averaging, euclidean_barycenter, softdtw_barycenter
  from tslearn.bases import BaseModelPackage, TimeSeriesBaseEstimator
  from tslearn.metrics import cdist_dtw, cdist_gak, cdist_soft_dtw, sigma_gak
  from tslearn.utils import check_dims, to_sklearn_dataset, to_time_series_dataset
  from .utils import EmptyClusterError, TimeSeriesCentroidBasedClusteringMixin, _check_full_length, _check_initial_guess, _check_no_empty_cluster, _compute_inertia
label_desc: Use image node_id 9 for calling the KernelKMeans obj's underlying member method code with example usage: obj._compute_inertia(dist_sq) and returns: dist_sq