class_docstr: K-means clustering for time-series data.
  
  Parameters
  ----------
  n_clusters : int (default: 3)
      Number of clusters to form.
  
  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.
  
  metric : {"euclidean", "dtw", "softdtw"} (default: "euclidean")
      Metric to be used for both cluster assignment and barycenter
      computation. If "dtw", DBA is used for barycenter
      computation.
  
  max_iter_barycenter : int (default: 100)
      Number of iterations for the barycenter computation process. Only used
      if `metric="dtw"` or `metric="softdtw"`.
  
  metric_params : dict or None (default: None)
      Parameter values for the chosen metric.
      For metrics that accept parallelization of the cross-distance matrix
      computations, `n_jobs` key passed in `metric_params` is overridden by
      the `n_jobs` argument.
  
  n_jobs : int or None, optional (default=None)
      The number of jobs to run in parallel for cross-distance matrix
      computations.
      Ignored if the cross-distance matrix cannot be computed using
      parallelization.
      ``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.
  
  dtw_inertia: bool (default: False)
      Whether to compute DTW inertia even if DTW is not the chosen metric.
  
  verbose : int (default: 0)
      If nonzero, print information about the inertia while learning
      the model and 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.
  
  init : {'k-means++', 'random' or an ndarray} (default: 'k-means++')
      Method for initialization:
      'k-means++' : use k-means++ heuristic. See `scikit-learn's k_init_
      <https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/        cluster/k_means_.py>`_ for more.
      '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, ts_size, d)
      and gives the initial centers.
  
  Attributes
  ----------
  labels_ : numpy.ndarray
      Labels of each point.
  
  cluster_centers_ : numpy.ndarray of shape (n_clusters, sz, d)
      Cluster centers.
      `sz` is the size of the time series used at fit time if the init method
      is 'k-means++' or 'random', and the size of the longest initial
      centroid if those are provided as a numpy array through init parameter.
  
  inertia_ : float
      Sum of distances of samples to their closest cluster center.
  
  n_iter_ : int
      The number of iterations performed during fit.
  
  Notes
  -----
      If `metric` is set to `"euclidean"`, the algorithm expects a dataset of
      equal-sized time series.
  
  Examples
  --------
  >>> from tslearn.generators import random_walks
  >>> X = random_walks(n_ts=50, sz=32, d=1)
  >>> km = TimeSeriesKMeans(n_clusters=3, metric="euclidean", max_iter=5,
  ...                       random_state=0).fit(X)
  >>> km.cluster_centers_.shape
  (3, 32, 1)
  >>> km_dba = TimeSeriesKMeans(n_clusters=3, metric="dtw", max_iter=5,
  ...                           max_iter_barycenter=5,
  ...                           random_state=0).fit(X)
  >>> km_dba.cluster_centers_.shape
  (3, 32, 1)
  >>> km_sdtw = TimeSeriesKMeans(n_clusters=3, metric="softdtw", max_iter=5,
  ...                            max_iter_barycenter=5,
  ...                            metric_params={"gamma": .5},
  ...                            random_state=0).fit(X)
  >>> km_sdtw.cluster_centers_.shape
  (3, 32, 1)
  >>> X_bis = to_time_series_dataset([[1, 2, 3, 4],
  ...                                 [1, 2, 3],
  ...                                 [2, 5, 6, 7, 8, 9]])
  >>> km = TimeSeriesKMeans(n_clusters=2, max_iter=5,
  ...                       metric="dtw", random_state=0).fit(X_bis)
  >>> km.cluster_centers_.shape
  (2, 6, 1)
class_docstr_tok: ["K-means","clustering","for","time-series","data",".","Parameters","--","--","--","--","--","n_clusters",":","int","(","default",":","3",")","Number","of","clusters","to","form",".","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",".","metric",":","{","``","euclidean","''",",","``","dtw","''",",","``","softdtw","''","}","(","default",":","``","euclidean","''",")","Metric","to","be","used","for","both","cluster","assignment","and","barycenter","computation",".","If","``","dtw","''",",","DBA","is","used","for","barycenter","computation",".","max_iter_barycenter",":","int","(","default",":","100",")","Number","of","iterations","for","the","barycenter","computation","process",".","Only","used","if","`","metric=","''","dtw","''","`","or","`","metric=","''","softdtw","''","`",".","metric_params",":","dict","or","None","(","default",":","None",")","Parameter","values","for","the","chosen","metric",".","For","metrics","that","accept","parallelization","of","the","cross-distance","matrix","computations",",","`","n_jobs","`","key","passed","in","`","metric_params","`","is","overridden","by","the","`","n_jobs","`","argument",".","n_jobs",":","int","or","None",",","optional","(","default=None",")","The","number","of","jobs","to","run","in","parallel","for","cross-distance","matrix","computations",".","Ignored","if","the","cross-distance","matrix","can","not","be","computed","using","parallelization",".","``","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",".","dtw_inertia",":","bool","(","default",":","False",")","Whether","to","compute","DTW","inertia","even","if","DTW","is","not","the","chosen","metric",".","verbose",":","int","(","default",":","0",")","If","nonzero",",","print","information","about","the","inertia","while","learning","the","model","and","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",".","init",":","{","'","k-means++","'",",","'random","'","or","an","ndarray","}","(","default",":","'","k-means++","'",")","Method","for","initialization",":","'","k-means++","'",":","use","k-means++","heuristic",".","See","`","scikit-learn","'s","k_init_","<","https",":","\/\/github.com\/scikit-learn\/scikit-learn\/blob\/master\/sklearn\/","cluster\/k_means_.py",">","`","_","for","more",".","'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",",","ts_size",",","d",")","and","gives","the","initial","centers",".","Attributes","--","--","--","--","--","labels_",":","numpy.ndarray","Labels","of","each","point",".","cluster_centers_",":","numpy.ndarray","of","shape","(","n_clusters",",","sz",",","d",")","Cluster","centers",".","`","sz","`","is","the","size","of","the","time","series","used","at","fit","time","if","the","init","method","is","'","k-means++","'","or","'random","'",",","and","the","size","of","the","longest","initial","centroid","if","those","are","provided","as","a","numpy","array","through","init","parameter",".","inertia_",":","float","Sum","of","distances","of","samples","to","their","closest","cluster","center",".","n_iter_",":","int","The","number","of","iterations","performed","during","fit",".","Notes","--","--","-","If","`","metric","`","is","set","to","`","``","euclidean","''","`",",","the","algorithm","expects","a","dataset","of","equal-sized","time","series",".","Examples","--","--","--","--",">",">",">","from","tslearn.generators","import","random_walks",">",">",">","X","=","random_walks","(","n_ts=50",",","sz=32",",","d=1",")",">",">",">","km","=","TimeSeriesKMeans","(","n_clusters=3",",","metric=","''","euclidean","''",",","max_iter=5",",","...","random_state=0",")",".fit","(","X",")",">",">",">","km.cluster_centers_.shape","(","3",",","32",",","1",")",">",">",">","km_dba","=","TimeSeriesKMeans","(","n_clusters=3",",","metric=","''","dtw","''",",","max_iter=5",",","...","max_iter_barycenter=5",",","...","random_state=0",")",".fit","(","X",")",">",">",">","km_dba.cluster_centers_.shape","(","3",",","32",",","1",")",">",">",">","km_sdtw","=","TimeSeriesKMeans","(","n_clusters=3",",","metric=","''","softdtw","''",",","max_iter=5",",","...","max_iter_barycenter=5",",","...","metric_params=","{","``","gamma","''",":",".5","}",",","...","random_state=0",")",".fit","(","X",")",">",">",">","km_sdtw.cluster_centers_.shape","(","3",",","32",",","1",")",">",">",">","X_bis","=","to_time_series_dataset","(","[","[","1",",","2",",","3",",","4","]",",","...","[","1",",","2",",","3","]",",","...","[","2",",","5",",","6",",","7",",","8",",","9","]","]",")",">",">",">","km","=","TimeSeriesKMeans","(","n_clusters=2",",","max_iter=5",",","...","metric=","''","dtw","''",",","random_state=0",")",".fit","(","X_bis",")",">",">",">","km.cluster_centers_.shape","(","2",",","6",",","1",")"]
code: def _assign(self, X, update_class_attributes=True):
      dists = self._transform(X)
      matched_labels = dists.argmin(axis=1)
      if update_class_attributes:
          self.labels_ = matched_labels
          _check_no_empty_cluster(self.labels_, self.n_clusters)
          if self.dtw_inertia and self.metric != "dtw":
              inertia_dists = cdist_dtw(
                  X,
                  self.cluster_centers_,
                  n_jobs=self.n_jobs,
                  verbose=self.verbose,
              )
          else:
              inertia_dists = dists
          self.inertia_ = _compute_inertia(
              inertia_dists, self.labels_, self._squared_inertia
          )
      return matched_labels
  
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 6 for calling the TimeSeriesKMeans obj's underlying member method code with example usage: obj._assign(X, update_class_attributes) and returns: matched_labels