I was working on a clustering based model and I read about hierarchical clustering and K-Means clustering.
Under what conditions should I choose agglomerative over K-means clustering?
Data Science Stack Exchange is a question and answer site for Data science professionals, Machine Learning specialists, and those interested in learning more about the field. It only takes a minute to sign up.Sign up to join this community
You can see this comparison table in sklearn, which gives some intuition about where and when each algorithm is successful:
It might be a good idea to try both and evaluate their accuracy, with an unsupervised clustering metric, like the silhouette score, to get an objective measure of their performance on a specific dataset.
Some other major differences are:
To add to WBM great citation, you should use K-means over Agglomerative when your final objetive is to use the trained algorithm to make inference over new unseen observations.
I will try to illustrate this with an example:
Imagine you have 2 models
aggcls both have been trained on data that correspond to information of customers on an specific domain (you are offering different credit cards), and your task is to form groups in order to see what product might be more interested each group on, imagine you have form the same number of clusters
n in both cases, among those
n groups there is one specially suitable for a premium credit card since that group has huge income, large number of transactions and also have more credit experience, so when a new customer arrives you want to evaluate him in order to know whether or no you can offer him the premium product.
kmeans model you would only need to make a
predict over the vector of characteristics of this new client to obtain the cluster this customer belongs to, whereas with
aggcls you will have to retrain the algorithm with the whole data including this new observation (not very useful right?)
This happens because of the nature of each algorithm, with kmeans, you will get n centroids that can be use to make inference of new unseen data by calculating the distance between the new instance and every cluster and then assign this new observation to the nearest one. With agglomerative, you do not generate any parameter that can be applied to new observations, you have to form your clusters again.