kmeans_scratch ,finding the optimal K with minimum ratio

  1. Randomly choosing Centroids
  2. finding the distance between centroids and all the data points using Euclidean distance formula
  3. Update the Centroid with the minimum Distance
  4. Repeating the above steps (1-3) for a defined number of iterations
  5. Return center,mean_intra_cluster_distance,mean_inter_cluster_distance

image

image

Sample output

image

Note : K -means algorithm does not guarantee to find the optimum. So when you run the script again and again the optimal ‘k’ value changes each time because of random tensor fake data.