class_docstr: A simple clustering method that forms k clusters by iteratively reassigning
  samples to the closest centroids and after that moves the centroids to the center
  of the new formed clusters.
  
  
  Parameters:
  -----------
  k: int
      The number of clusters the algorithm will form.
  max_iterations: int
      The number of iterations the algorithm will run for if it does
      not converge before that. 
class_docstr_tok: ["A","simple","clustering","method","that","forms","k","clusters","by","iteratively","reassigning","samples","to","the","closest","centroids","and","after","that","moves","the","centroids","to","the","center","of","the","new","formed","clusters",".","Parameters",":","--","--","--","--","--","-","k",":","int","The","number","of","clusters","the","algorithm","will","form",".","max_iterations",":","int","The","number","of","iterations","the","algorithm","will","run","for","if","it","does","not","converge","before","that","."]
docstr: Do K-Means clustering and return cluster indices 
docstr_tok: ["Do","K-Means","clustering","and","return","cluster","indices"]
code: def predict(self, X):
      """Do K-Means clustering and return cluster indices"""
  
      # Initialize centroids as k random samples from X
      centroids = self._init_random_centroids(X)
  
      # Iterate until convergence or for max iterations
      for _ in range(self.max_iterations):
          # Assign samples to closest centroids (create clusters)
          clusters = self._create_clusters(centroids, X)
          # Save current centroids for convergence check
          prev_centroids = centroids
          # Calculate new centroids from the clusters
          centroids = self._calculate_centroids(clusters, X)
          # If no centroids have changed => convergence
          diff = centroids - prev_centroids
          if not diff.any():
              break
  
      return self._get_cluster_labels(clusters, X)
  
file_path: ML-From-Scratch/mlfromscratch/unsupervised_learning/k_means.py
imports: from __future__ import print_function, division
  import numpy
  from mlfromscratch.utils import normalize, euclidean_distance, Plot
  from mlfromscratch.unsupervised_learning import *
label_desc: Use image node_id 7 for calling the KMeans obj's underlying member method code with example usage: obj.predict(X) and returns: self