I have a big data (100k + records) set that I have divided into two clusters using KMeans. I also have an array with the cluster centers and I can easily compute the squared distance of each data point to the cluster center.

How can I use this distance to identify the possible outliers? What should I use as a threshold so I can compare that to the distance and properly identify possible outliers?


1 Answer 1


Firstly note, that the result of Kmeans with random initialization is not robust (Different resulting cluster centers for each run).

Further the choice of the parameter k further influences your outlier detection and potentially deserves a discussion.

Relevant further material to read on the subject would be:

How to understand the drawbacks of K-means

How to decide on the correct number of clusters?

Assuming that you already informed yourself about both problems and that your current two clusters are exactly what you want, we can now arbitrarily define outliers.

After computing the distance of each datapoint to its cluster center, you can use the x - percentile distance as a threshold. The choice of x depends on the problem you are working on such as the importance of outlier detection. If false negatives are problematic, you better choose a lower value such as x = 90%. Yet if false positives are problematic, you will choose a higher value such as x = 99%.

That beeing said, you might want to have a look into the DBSCAN algorithm which combines outlier detection and clustering nicely and does not require you to predefine the number of clusters:



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.