How to visualize kmeans clustering on multidimensional data

asdlfkjlkj picture asdlfkjlkj · Oct 20, 2017 · Viewed 11.2k times · Source

I am using kmeans clustering algorithm on mnist dataset and want to visualize the plots after clustering. So far I did this

from mnist import MNIST

mndata = MNIST('Datasets')
X_train, y_train = mndata.load_training()

#do the clustering
k_means = cluster.KMeans(n_clusters=len(np.unique(y_train)))
k_means.fit(X_train)
labels = k_means.labels_

So, I now have 10 clusters representing 0 to 9. How can I visualize these clusters?

Answer

Charlotte Rogers picture Charlotte Rogers · Nov 9, 2017

You can visualise multi-dimensional clustering using pandas plotting tool parallel_coordinates.

predict = k_means.predict(data)
data['cluster'] = predict
pandas.tools.plotting.parallel_coordinates(data, 'cluster')