I managed to create a dataset with 6 clusters and visualize it with the code below, now I would like to visualize demonstration of update of the cluster centroids in KMeans algorithm. This demonstration should include first four iterations by generating 2×2-axis figure
Here is my code:
# import statements
from sklearn.datasets import make_blobs
import numpy as np
import matplotlib.pyplot as plt
# create blobs
data = make_blobs(n_samples=200, n_features=6, centers=6, cluster_std=1.6, random_state=50)
# create np array for data points
points = data[0]
# create scatter plot
plt.scatter(data[0][:,0], data[0][:,1], c=data[1], cmap='jet',marker="+",label="Original Data")
plt.xlim(-15,15)
plt.ylim(-15,15)
plt.show()
How can I implement this algorithm? It has been asked before using R but, I would like to do it in python. Can you help me visualize the first 4 iterations?
Output should be like: