class_docstr: Abstract class that implements time series Lloyds algorithm.
  
  Parameters
  ----------
  n_clusters: int, defaults = 8
      The number of clusters to form as well as the number of
      centroids to generate.
  init_algorithm: str, np.ndarray (3d array of shape (n_clusters, n_dimensions,
      series_length)), defaults = 'forgy'
      Method for initializing cluster centers or an array of initial cluster centers.
      Any of the following strings are valid: ['kmeans++', 'random', 'forgy']
  metric: str or Callable, defaults = 'dtw'
      Distance metric to compute similarity between time series. Any of the following
      are valid: ['dtw', 'euclidean', 'erp', 'edr', 'lcss', 'squared', 'ddtw', 'wdtw',
      'wddtw']
  n_init: int, defaults = 10
      Number of times the k-means algorithm will be run with different
      centroid seeds. The final result will be the best output of n_init
      consecutive runs in terms of inertia.
  max_iter: int, defaults = 30
      Maximum number of iterations of the k-means algorithm for a single
      run.
  tol: float, defaults = 1e-6
      Relative tolerance with regards to Frobenius norm of the difference
      in the cluster centers of two consecutive iterations to declare
      convergence.
  verbose: bool, defaults = False
      Verbosity mode.
  random_state: int or np.random.RandomState instance or None, defaults = None
      Determines random number generation for centroid initialization.
  distance_params: dict, defaults = None
      Dictionary containing kwargs for the distance metric being used.
  
  Attributes
  ----------
  cluster_centers_: np.ndarray (3d array of shape (n_clusters, n_dimensions,
      series_length))
      Time series that represent each of the cluster centers. If the algorithm stops
      before fully converging these will not be consistent with labels_.
  labels_: np.ndarray (1d array of shape (n_instance,))
      Labels that is the index each time series belongs to.
  inertia_: float
      Sum of squared distances of samples to their closest cluster center, weighted by
      the sample weights if provided.
  n_iter_: int
      Number of iterations run.
class_docstr_tok: ["Abstract","class","that","implements","time","series","Lloyds","algorithm",".","Parameters","--","--","--","--","--","n_clusters",":","int",",","defaults","=","8","The","number","of","clusters","to","form","as","well","as","the","number","of","centroids","to","generate",".","init_algorithm",":","str",",","np.ndarray","(","3d","array","of","shape","(","n_clusters",",","n_dimensions",",","series_length",")",")",",","defaults","=","'forgy'","Method","for","initializing","cluster","centers","or","an","array","of","initial","cluster","centers",".","Any","of","the","following","strings","are","valid",":","[","'kmeans++","'",",","'random","'",",","'forgy","'","]","metric",":","str","or","Callable",",","defaults","=","'dtw'","Distance","metric","to","compute","similarity","between","time","series",".","Any","of","the","following","are","valid",":","[","'dtw","'",",","'euclidean","'",",","'erp","'",",","'edr","'",",","'lcss","'",",","'squared","'",",","'ddtw","'",",","'wdtw","'",",","'wddtw","'","]","n_init",":","int",",","defaults","=","10","Number","of","times","the","k-means","algorithm","will","be","run","with","different","centroid","seeds",".","The","final","result","will","be","the","best","output","of","n_init","consecutive","runs","in","terms","of","inertia",".","max_iter",":","int",",","defaults","=","30","Maximum","number","of","iterations","of","the","k-means","algorithm","for","a","single","run",".","tol",":","float",",","defaults","=","1e-6","Relative","tolerance","with","regards","to","Frobenius","norm","of","the","difference","in","the","cluster","centers","of","two","consecutive","iterations","to","declare","convergence",".","verbose",":","bool",",","defaults","=","False","Verbosity","mode",".","random_state",":","int","or","np.random.RandomState","instance","or","None",",","defaults","=","None","Determines","random","number","generation","for","centroid","initialization",".","distance_params",":","dict",",","defaults","=","None","Dictionary","containing","kwargs","for","the","distance","metric","being","used",".","Attributes","--","--","--","--","--","cluster_centers_",":","np.ndarray","(","3d","array","of","shape","(","n_clusters",",","n_dimensions",",","series_length",")",")","Time","series","that","represent","each","of","the","cluster","centers",".","If","the","algorithm","stops","before","fully","converging","these","will","not","be","consistent","with","labels_",".","labels_",":","np.ndarray","(","1d","array","of","shape","(","n_instance",",",")",")","Labels","that","is","the","index","each","time","series","belongs","to",".","inertia_",":","float","Sum","of","squared","distances","of","samples","to","their","closest","cluster","center",",","weighted","by","the","sample","weights","if","provided",".","n_iter_",":","int","Number","of","iterations","run","."]
docstr: Perform one pass of kmeans.
  
  This is done because the initial center assignment greatly effects the final
  result so we perform multiple passes at kmeans with different initial center
  assignments and keep the best results going forward.
  
  Parameters
  ----------
  X : np.ndarray (2d or 3d array of shape (n_instances, series_length) or shape
      (n_instances, n_dimensions, series_length))
      Training time series instances to cluster.
  y: ignored, exists for API consistency reasons.
  
  Returns
  -------
  np.ndarray (1d array of shape (n_instance,))
      Labels that is the index each time series belongs to.
  np.ndarray (3d array of shape (n_clusters, n_dimensions,
      series_length))
      Time series that represent each of the cluster centres. If the algorithm
      stops before fully converging these will not be consistent with labels.
  float
      Sum of squared distances of samples to their closest cluster center,
      weighted by the sample weights if provided.
docstr_tok: ["Perform","one","pass","of","kmeans",".","This","is","done","because","the","initial","center","assignment","greatly","effects","the","final","result","so","we","perform","multiple","passes","at","kmeans","with","different","initial","center","assignments","and","keep","the","best","results","going","forward",".","Parameters","--","--","--","--","--","X",":","np.ndarray","(","2d","or","3d","array","of","shape","(","n_instances",",","series_length",")","or","shape","(","n_instances",",","n_dimensions",",","series_length",")",")","Training","time","series","instances","to","cluster",".","y",":","ignored",",","exists","for","API","consistency","reasons",".","Returns","--","--","--","-","np.ndarray","(","1d","array","of","shape","(","n_instance",",",")",")","Labels","that","is","the","index","each","time","series","belongs","to",".","np.ndarray","(","3d","array","of","shape","(","n_clusters",",","n_dimensions",",","series_length",")",")","Time","series","that","represent","each","of","the","cluster","centres",".","If","the","algorithm","stops","before","fully","converging","these","will","not","be","consistent","with","labels",".","float","Sum","of","squared","distances","of","samples","to","their","closest","cluster","center",",","weighted","by","the","sample","weights","if","provided","."]
code: def _fit_one_init(
      self, X
  ) -> Tuple[np.ndarray, np.ndarray, float, int]:
      """Perform one pass of kmeans.
  
      This is done because the initial center assignment greatly effects the final
      result so we perform multiple passes at kmeans with different initial center
      assignments and keep the best results going forward.
  
      Parameters
      ----------
      X : np.ndarray (2d or 3d array of shape (n_instances, series_length) or shape
          (n_instances, n_dimensions, series_length))
          Training time series instances to cluster.
      y: ignored, exists for API consistency reasons.
  
      Returns
      -------
      np.ndarray (1d array of shape (n_instance,))
          Labels that is the index each time series belongs to.
      np.ndarray (3d array of shape (n_clusters, n_dimensions,
          series_length))
          Time series that represent each of the cluster centres. If the algorithm
          stops before fully converging these will not be consistent with labels.
      float
          Sum of squared distances of samples to their closest cluster center,
          weighted by the sample weights if provided.
      """
      if isinstance(self._init_algorithm, np.ndarray):
          cluster_centres = self._init_algorithm
      else:
          cluster_centres = self._init_algorithm(
              X,
              self.n_clusters,
              self._random_state,
              distance_metric=self._distance_metric,
          )
      old_inertia = np.inf
      old_labels = None
      for i in range(self.max_iter):
          labels, inertia = self._assign_clusters(
              X,
              cluster_centres,
          )
  
          if np.abs(old_inertia - inertia) < self.tol:
              break
          old_inertia = inertia
  
          if np.array_equal(labels, old_labels):
              if self.verbose:
                  print(  # noqa: T201
                      f"Converged at iteration {i}: strict convergence."
                  )
              break
          old_labels = labels
  
          cluster_centres = self._compute_new_cluster_centers(X, labels)
  
          if self.verbose is True:
              print(f"Iteration {i}, inertia {inertia}.")  # noqa: T201
  
      labels, inertia = self._assign_clusters(X, cluster_centres)
      centres = cluster_centres
  
      return labels, centres, inertia, i + 1
  
imports: from abc import ABC, abstractmethod
  from typing import Callable, Tuple, Union
  import numpy
  from numpy.random import RandomState
  from sklearn.utils import check_random_state
  from sklearn.utils.extmath import stable_cumsum
  from sktime.clustering.base import BaseClusterer
  from sktime.clustering.metrics.averaging import mean_average
  from sktime.distances import distance_factory, pairwise_distance
  from sktime.distances._ddtw import average_of_slope_transform
label_desc: Use image node_id 5 for calling the TimeSeriesLloyds obj's underlying member method code with example usage: obj._fit_one_init(X) and returns: labels,  centres,  inertia,  unknown