0

So I have created a K-means algorithm from scratch and what I want to do is to plot each iteration. So if the K-means runs 5 times I want 5 plots so you can visualize how the centroids and the clusters change. And i'm stuck on how to even start this proccess. Would I store all the clusters and centroids with each iteration to a list? I tried doing that but it gets so confusing to later plot and run a for loop through the list.

If the question is confusing let me know and i'll try to explain it better.

This is my code I have so far to plot the centroids and clusters.

    for i, cluster in enumerate(clusters):
        cluster = np.array(cluster)
        plt.scatter(cluster[:, 0], cluster[:, 1], c=colors[i])
    for center in centers:
        plt.scatter(center[0], center[1], c="k", marker="x", s=100)
    plt.title("Iteration {}".format(k))
    plt.show()

Now all this does is just plot the final result, since the variable clusters and centers are the returns of my Kmeans function. Any ideas? Thanks in advance.

MikeHD
  • 1
  • 1

0 Answers0