docstr: Parameters
  ----------
  n_clusters : int, optional, default: 4
      The number of clusters to form as well as the number of medoids to
      generate.
  
  metric : string, or callable, optional, default: 'euclidean'
      What distance metric to use. See :func:metrics.pairwise_distances
      metric can be 'precomputed', the user must then feed the fit method
      with a precomputed kernel matrix and not the design matrix X.
  
  init : {'random', 'heuristic'}, optional, default: 'random'
      Specify medoid initialization method. 'random' selects n_clusters
      elements from the dataset. 'heuristic' picks the n_clusters points
      with the smallest sum distance to every other point.
  
  max_iter : int, optional, default : 300
      Specify the maximum number of iterations when fitting. It can be zero in
      which case only the initialization is computed which may be suitable for
      large datasets when the initialization is sufficiently efficient
  
  random_state : int, RandomState instance or None, optional
      Specify random state for the random number generator. Used to
      initialise medoids when init='random'.
  
  Attributes
  ----------
  cluster_centers_ : array, shape = (n_clusters, n_features)
          or None if metric == 'precomputed'
      Cluster centers, i.e. medoids (elements from the original dataset)
  
  medoid_indices_ : array, shape = (n_clusters,)
      The indices of the medoid rows in X
  
  labels_ : array, shape = (n_samples,)
      Labels of each point
  
  inertia_ : float
      Sum of distances of samples to their closest cluster center.
  
  score_ : float
      Negative of the inertia. The more negative the score, the higher the variation in cluster points, the worse the clustering.
docstr_tok: ["Parameters","--","--","--","--","--","n_clusters",":","int",",","optional",",","default",":","4","The","number","of","clusters","to","form","as","well","as","the","number","of","medoids","to","generate",".","metric",":","string",",","or","callable",",","optional",",","default",":","'euclidean'","What","distance","metric","to","use",".","See",":","func",":","metrics.pairwise_distances","metric","can","be","'precomputed","'",",","the","user","must","then","feed","the","fit","method","with","a","precomputed","kernel","matrix","and","not","the","design","matrix","X.","init",":","{","'random","'",",","'heuristic","'","}",",","optional",",","default",":","'random'","Specify","medoid","initialization","method",".","'random","'","selects","n_clusters","elements","from","the","dataset",".","'heuristic","'","picks","the","n_clusters","points","with","the","smallest","sum","distance","to","every","other","point",".","max_iter",":","int",",","optional",",","default",":","300","Specify","the","maximum","number","of","iterations","when","fitting",".","It","can","be","zero","in","which","case","only","the","initialization","is","computed","which","may","be","suitable","for","large","datasets","when","the","initialization","is","sufficiently","efficient","random_state",":","int",",","RandomState","instance","or","None",",","optional","Specify","random","state","for","the","random","number","generator",".","Used","to","initialise","medoids","when","init='random","'",".","Attributes","--","--","--","--","--","cluster_centers_",":","array",",","shape","=","(","n_clusters",",","n_features",")","or","None","if","metric","==","'precomputed'","Cluster","centers",",","i.e",".","medoids","(","elements","from","the","original","dataset",")","medoid_indices_",":","array",",","shape","=","(","n_clusters",",",")","The","indices","of","the","medoid","rows","in","X","labels_",":","array",",","shape","=","(","n_samples",",",")","Labels","of","each","point","inertia_",":","float","Sum","of","distances","of","samples","to","their","closest","cluster","center",".","score_",":","float","Negative","of","the","inertia",".","The","more","negative","the","score",",","the","higher","the","variation","in","cluster","points",",","the","worse","the","clustering","."]
code: def __init__(
      self,
      n_clusters=4,
      metric="euclidean",
      init="random",
      max_iter=300,
      random_state=None,
  ):
      """Parameters
      ----------
      n_clusters : int, optional, default: 4
          The number of clusters to form as well as the number of medoids to
          generate.
  
      metric : string, or callable, optional, default: 'euclidean'
          What distance metric to use. See :func:metrics.pairwise_distances
          metric can be 'precomputed', the user must then feed the fit method
          with a precomputed kernel matrix and not the design matrix X.
  
      init : {'random', 'heuristic'}, optional, default: 'random'
          Specify medoid initialization method. 'random' selects n_clusters
          elements from the dataset. 'heuristic' picks the n_clusters points
          with the smallest sum distance to every other point.
  
      max_iter : int, optional, default : 300
          Specify the maximum number of iterations when fitting. It can be zero in
          which case only the initialization is computed which may be suitable for
          large datasets when the initialization is sufficiently efficient
  
      random_state : int, RandomState instance or None, optional
          Specify random state for the random number generator. Used to
          initialise medoids when init='random'.
  
      Attributes
      ----------
      cluster_centers_ : array, shape = (n_clusters, n_features)
              or None if metric == 'precomputed'
          Cluster centers, i.e. medoids (elements from the original dataset)
  
      medoid_indices_ : array, shape = (n_clusters,)
          The indices of the medoid rows in X
  
      labels_ : array, shape = (n_samples,)
          Labels of each point
  
      inertia_ : float
          Sum of distances of samples to their closest cluster center.
  
      score_ : float
          Negative of the inertia. The more negative the score, the higher the variation in cluster points, the worse the clustering.
      """
  
      self.n_clusters = n_clusters
      self.metric = metric
      self.init = init
      self.max_iter = max_iter
      self.random_state = random_state
  
imports: import warnings
  import numpy
  from sklearn.base import BaseEstimator, ClusterMixin
  from sklearn.exceptions import ConvergenceWarning
  from sklearn.metrics.pairwise import pairwise_distances, pairwise_distances_argmin
  from sklearn.utils import check_array
  from sklearn.utils.validation import check_is_fitted
label_desc: Use image node_id 1 to create a new KMedoids object from inherited base classes: BaseEstimator, ClusterMixin with example: obj = KMedoids(n_clusters, metric, init, max_iter, random_state)