# Compute Accuracy of k-means [duplicate]

Could you please provide me an example of how I can compute the accuracy for a kmeans clustering? I split my dataset into train and test sets and computed the predicted clusters for the train set. However, I do not know how to compiute its level of accuracy and see if it is good not also for the test.

An example with a sample dataset of your choice it would be extremely useful.

• Do you mean k-nearest neighbors? – Dave May 24 at 12:12

K-Means is a clustering technique NOT classification. You don't have the ground truth here to compare with. Hence accuracy doesn't make any sense.

You can train the model and with the test data predict which cluster the test data belongs to.

Try to visualize it, it shall be helpful.

• What about this? I was wondering how they found the accuracy from l-means clustering analysis using their dataset. towardsdatascience.com/… – Dave May 23 at 13:44
• They are just calculating how many instance are predicted correctly out of all the instance since they have labelled dataset which IS accuracy since they HAVE labels. Clustering is unsupervised method where we don't have labelled data hence we can't compare it with against anything.k-means is clustering technique which they used with labelled data. We are just trying to find the structure/clusters in unsupervised method. This article gives you the idea on how to use k means and how does it work to better understand the flow. – BlackCurrant May 23 at 14:02

Like user @BlackCurrant has mentioned, there is no single source of truth in unsupervised methods

However,If you want to validate the quality of clusters formed, below are a few things that can be tried

1. Test of quality of clusters: use Sillhouette coefficient or CH index

2. Test of robustness: randomly sample 90% of data from each cluster and form a new dataset.Now rerun k means with same k and check if the clusters have significantly changed. This would indicate whether the clusters were highly influenced by outliers

3. Test of stability: if your data is time dependant, check intercluster movements

4. Visualize

There is no universally agreed validation methods for clustering