class_docstr: !
  @brief Class represents clustering algorithm K-Medians.
  @details The algorithm is less sensitive to outliers than K-Means. Medians are calculated instead of centroids.
  
  Example:
  @code
      from pyclustering.cluster.kmedians import kmedians
      from pyclustering.cluster import cluster_visualizer
      from pyclustering.utils import read_sample
      from pyclustering.samples.definitions import FCPS_SAMPLES
  
      # Load list of points for cluster analysis.
      sample = read_sample(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS)
  
      # Create instance of K-Medians algorithm.
      initial_medians = [[0.0, 0.1], [2.5, 0.7]]
      kmedians_instance = kmedians(sample, initial_medians)
  
      # Run cluster analysis and obtain results.
      kmedians_instance.process()
      clusters = kmedians_instance.get_clusters()
      medians = kmedians_instance.get_medians()
  
      # Visualize clustering results.
      visualizer = cluster_visualizer()
      visualizer.append_clusters(clusters, sample)
      visualizer.append_cluster(initial_medians, marker='*', markersize=10)
      visualizer.append_cluster(medians, marker='*', markersize=10)
      visualizer.show()
  @endcode
class_docstr_tok: ["!","@","brief","Class","represents","clustering","algorithm","K-Medians",".","@","details","The","algorithm","is","less","sensitive","to","outliers","than","K-Means",".","Medians","are","calculated","instead","of","centroids",".","Example",":","@","code","from","pyclustering.cluster.kmedians","import","kmedians","from","pyclustering.cluster","import","cluster_visualizer","from","pyclustering.utils","import","read_sample","from","pyclustering.samples.definitions","import","FCPS_SAMPLES","#","Load","list","of","points","for","cluster","analysis",".","sample","=","read_sample","(","FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS",")","#","Create","instance","of","K-Medians","algorithm",".","initial_medians","=","[","[","0.0",",","0.1","]",",","[","2.5",",","0.7","]","]","kmedians_instance","=","kmedians","(","sample",",","initial_medians",")","#","Run","cluster","analysis","and","obtain","results",".","kmedians_instance.process","(",")","clusters","=","kmedians_instance.get_clusters","(",")","medians","=","kmedians_instance.get_medians","(",")","#","Visualize","clustering","results",".","visualizer","=","cluster_visualizer","(",")","visualizer.append_clusters","(","clusters",",","sample",")","visualizer.append_cluster","(","initial_medians",",","marker=","'","*","'",",","markersize=10",")","visualizer.append_cluster","(","medians",",","marker=","'","*","'",",","markersize=10",")","visualizer.show","(",")","@","endcode"]
docstr: !
  @brief Performs cluster analysis in line with rules of K-Medians algorithm.
  
  @return (kmedians) Returns itself (K-Medians instance).
  
  @remark Results of clustering can be obtained using corresponding get methods.
  
  @see get_clusters()
  @see get_medians()
docstr_tok: ["!","@","brief","Performs","cluster","analysis","in","line","with","rules","of","K-Medians","algorithm",".","@","return","(","kmedians",")","Returns","itself","(","K-Medians","instance",")",".","@","remark","Results","of","clustering","can","be","obtained","using","corresponding","get","methods",".","@","see","get_clusters","(",")","@","see","get_medians","(",")"]
code: def process(self):
      """!
      @brief Performs cluster analysis in line with rules of K-Medians algorithm.
  
      @return (kmedians) Returns itself (K-Medians instance).
  
      @remark Results of clustering can be obtained using corresponding get methods.
  
      @see get_clusters()
      @see get_medians()
  
      """
  
      if self.__ccore is True:
          ccore_metric = metric_wrapper.create_instance(self.__metric)
          self.__clusters, self.__medians = wrapper.kmedians(
              self.__pointer_data,
              self.__medians,
              self.__tolerance,
              self.__itermax,
              ccore_metric.get_pointer(),
          )
  
      else:
          changes = float("inf")
  
          # Check for dimension
          if len(self.__pointer_data[0]) != len(self.__medians[0]):
              raise NameError(
                  "Dimension of the input data and dimension of the initial medians must be equal."
              )
  
          iterations = 0
          while (
              changes > self.__tolerance and iterations < self.__itermax
          ):
              self.__clusters = self.__update_clusters()
              updated_centers = self.__update_medians()
  
              changes = max(
                  [
                      self.__metric(
                          self.__medians[index], updated_centers[index]
                      )
                      for index in range(len(updated_centers))
                  ]
              )
  
              self.__medians = updated_centers
  
              iterations += 1
  
      self.__calculate_total_wce()
  
      return self
  
file_path: pyclustering/pyclustering/cluster/kmedians.py
imports: import math
  import numpy
  from pyclustering.cluster.encoder import type_encoding
  from pyclustering.utils.metric import distance_metric, type_metric
  import pyclustering.core.kmedians_wrapper
  from pyclustering.core.wrapper import ccore_library
  from pyclustering.core.metric_wrapper import metric_wrapper
label_desc: Use image node_id 2 for calling the kmedians obj's underlying member method code with example usage: obj.process() and returns: self