# Applying and Visualizing k means clustering on a data set that has 9 features

I had a data set of images that I have extracted 9 numerical features that I want to apply k means clustering or hierarchical clustering to. I'm just not sure how to go about it. The tutorials I have read all only have 2 or 3 features to them, so it's easy to apply and graph. Any help would be appreciated

Here's the code I have so far:

numpyArr = df.values

ms = MeanShift()
ms.fit(numpyArr)
labels = ms.labels_
cluster_centers = ms.cluster_centers_
n_clusters_ = len(np.unique(labels))
print("Number of estimated clusters:", n_clusters_)


You may use a dimensionality reduction algorithm like PCA method after performing clustering, to reduce the dimension of your clustered data into two dimensions and then visualize the clusters.

• So I would apply normal clustering using my data set then use PCA to visualize it? How would I go about doing that – somedude1234 Jul 30 '19 at 12:36
• Yes exactly. Please check the following link medium.com/@dmitriy.kavyazin/… – Christos Karatsalos Jul 30 '19 at 13:57
• oh wow great article. I'll def try this out. Thank you! – somedude1234 Jul 30 '19 at 14:02
• @somedude1234 you are welcome! – Christos Karatsalos Jul 30 '19 at 16:24

Same as visualizing 9 dimensional data:

• scatter plot matrix with 9x9 scatterplots
• dimensionality reduction
• parallel coordinates
• whisker plots
• ...

If you want to visualise the data after K-Means, the better approach would be to reduce the dimensionality to two or three dimensions and visualise using a matplotlib 2D or 3D plot. You might also try pair plots but I don't think It would be much helpful from clustering stand point.