class_docstr: !
  @brief Class implements K-Means clustering algorithm.
  @details K-Means clustering aims to partition n observations into k clusters in which each observation belongs to
            the cluster with the nearest mean, serving as a prototype of the cluster. This results in a partitioning
            of the data space into Voronoi cells.
  
  K-Means clustering results depend on initial centers. Algorithm K-Means++ can used for initialization of
  initial centers - see module 'pyclustering.cluster.center_initializer'.
  
  CCORE implementation (C/C++ part of the library) of the algorithm performs parallel processing to ensure maximum
  performance.
  
  Implementation based on the paper @cite inproceedings::kmeans::1.
  
  @image html kmeans_example_clustering.png "Fig. 1. K-Means clustering results. At the left - 'Simple03.data' sample, at the right - 'Lsun.data' sample."
  
  Example #1 - Clustering using K-Means++ for center initialization:
  @code
      from pyclustering.cluster.kmeans import kmeans, kmeans_visualizer
      from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer
      from pyclustering.samples.definitions import FCPS_SAMPLES
      from pyclustering.utils import read_sample
  
      # Load list of points for cluster analysis.
      sample = read_sample(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS)
  
      # Prepare initial centers using K-Means++ method.
      initial_centers = kmeans_plusplus_initializer(sample, 2).initialize()
  
      # Create instance of K-Means algorithm with prepared centers.
      kmeans_instance = kmeans(sample, initial_centers)
  
      # Run cluster analysis and obtain results.
      kmeans_instance.process()
      clusters = kmeans_instance.get_clusters()
      final_centers = kmeans_instance.get_centers()
  
      # Visualize obtained results
      kmeans_visualizer.show_clusters(sample, clusters, final_centers)
  @endcode
  
  Example #2 - Clustering using specific distance metric, for example, Manhattan distance:
  @code
      # prepare input data and initial centers for cluster analysis using K-Means
  
      # create metric that will be used for clustering
      manhattan_metric = distance_metric(type_metric.MANHATTAN)
  
      # create instance of K-Means using specific distance metric:
      kmeans_instance = kmeans(sample, initial_centers, metric=manhattan_metric)
  
      # run cluster analysis and obtain results
      kmeans_instance.process()
      clusters = kmeans_instance.get_clusters()
  @endcode
  
  Implementation based on paper @cite inproceedings::kmeans::1.
  
  @see center_initializer
docstr: !
  @brief Constructor of clustering algorithm K-Means.
  @details Center initializer can be used for creating initial centers, for example, K-Means++ method.
  
  @param[in] data (array_like): Input data that is presented as array of points (objects), each point should be represented by array_like data structure.
  @param[in] initial_centers (array_like): Initial coordinates of centers of clusters that are represented by array_like data structure: [center1, center2, ...].
  @param[in] tolerance (double): Stop condition: if maximum value of change of centers of clusters is less than tolerance then algorithm stops processing.
  @param[in] ccore (bool): Defines should be CCORE library (C++ pyclustering library) used instead of Python code or not.
  @param[in] **kwargs: Arbitrary keyword arguments (available arguments: 'observer', 'metric', 'itermax').
  
  <b>Keyword Args:</b><br>
      - observer (kmeans_observer): Observer of the algorithm to collect information about clustering process on each iteration.
      - metric (distance_metric): Metric that is used for distance calculation between two points (by default euclidean square distance).
      - itermax (uint): Maximum number of iterations that is used for clustering process (by default: 200).
  
  @see center_initializer
docstr_tok: ["!","@","brief","Constructor","of","clustering","algorithm","K-Means",".","@","details","Center","initializer","can","be","used","for","creating","initial","centers",",","for","example",",","K-Means++","method",".","@","param","[","in","]","data","(","array_like",")",":","Input","data","that","is","presented","as","array","of","points","(","objects",")",",","each","point","should","be","represented","by","array_like","data","structure",".","@","param","[","in","]","initial_centers","(","array_like",")",":","Initial","coordinates","of","centers","of","clusters","that","are","represented","by","array_like","data","structure",":","[","center1",",","center2",",","...","]",".","@","param","[","in","]","tolerance","(","double",")",":","Stop","condition",":","if","maximum","value","of","change","of","centers","of","clusters","is","less","than","tolerance","then","algorithm","stops","processing",".","@","param","[","in","]","ccore","(","bool",")",":","Defines","should","be","CCORE","library","(","C++","pyclustering","library",")","used","instead","of","Python","code","or","not",".","@","param","[","in","]","*","*","kwargs",":","Arbitrary","keyword","arguments","(","available","arguments",":","'observer","'",",","'metric","'",",","'itermax","'",")",".","<","b",">","Keyword","Args",":","<","\/b",">","<","br",">","-","observer","(","kmeans_observer",")",":","Observer","of","the","algorithm","to","collect","information","about","clustering","process","on","each","iteration",".","-","metric","(","distance_metric",")",":","Metric","that","is","used","for","distance","calculation","between","two","points","(","by","default","euclidean","square","distance",")",".","-","itermax","(","uint",")",":","Maximum","number","of","iterations","that","is","used","for","clustering","process","(","by","default",":","200",")",".","@","see","center_initializer"]
code: def __init__(
      self, data, initial_centers, tolerance=0.001, ccore=True, **kwargs
  ):
      """!
      @brief Constructor of clustering algorithm K-Means.
      @details Center initializer can be used for creating initial centers, for example, K-Means++ method.
  
      @param[in] data (array_like): Input data that is presented as array of points (objects), each point should be represented by array_like data structure.
      @param[in] initial_centers (array_like): Initial coordinates of centers of clusters that are represented by array_like data structure: [center1, center2, ...].
      @param[in] tolerance (double): Stop condition: if maximum value of change of centers of clusters is less than tolerance then algorithm stops processing.
      @param[in] ccore (bool): Defines should be CCORE library (C++ pyclustering library) used instead of Python code or not.
      @param[in] **kwargs: Arbitrary keyword arguments (available arguments: 'observer', 'metric', 'itermax').
  
      <b>Keyword Args:</b><br>
          - observer (kmeans_observer): Observer of the algorithm to collect information about clustering process on each iteration.
          - metric (distance_metric): Metric that is used for distance calculation between two points (by default euclidean square distance).
          - itermax (uint): Maximum number of iterations that is used for clustering process (by default: 200).
  
      @see center_initializer
  
      """
      self.__pointer_data = numpy.array(data)
      self.__clusters = []
      self.__centers = numpy.array(initial_centers)
      self.__tolerance = tolerance
      self.__total_wce = 0.0
  
      self.__observer = kwargs.get("observer", None)
      self.__metric = copy.copy(
          kwargs.get(
              "metric", distance_metric(type_metric.EUCLIDEAN_SQUARE)
          )
      )
      self.__itermax = kwargs.get("itermax", 100)
  
      if self.__metric.get_type() != type_metric.USER_DEFINED:
          self.__metric.enable_numpy_usage()
      else:
          self.__metric.disable_numpy_usage()
  
      self.__ccore = (
          ccore and self.__metric.get_type() != type_metric.USER_DEFINED
      )
      if self.__ccore is True:
          self.__ccore = ccore_library.workable()
  
      self.__verify_arguments()
  
imports: import copy
  import numpy
  import matplotlib.pyplot
  import matplotlib.animation
  import pyclustering.core.kmeans_wrapper
  from pyclustering.core.wrapper import ccore_library
  from pyclustering.core.metric_wrapper import metric_wrapper
  from pyclustering.cluster.encoder import type_encoding
  from pyclustering.cluster import cluster_visualizer
  from pyclustering.utils.metric import distance_metric, type_metric
label_desc: Use image node_id 1 to create a new kmeans object  with example: obj = kmeans(data, initial_centers, tolerance, ccore)