# Confused between K-Means and Hierarchical Clustering for 9 different categories

I am trying to classify 9 different species of elephants into clusters using unsupervised learning. I have the following data about them:

• Their height
• Eye Colour
• Sound they produce in decibel (dB)

I know there are 9 different elephant species in total. However, I am unsure which algorithm would work better. My dataset size is not too huge, so I was wondering if K-Means would be a general worse option here (as Hierarchical Clustering seem to give the same results on every run unlike K-Means).

Any guidance on this would be helpful, thank you.

• Eye colour is categorical, isn't it? How would you use that with k-means? Actually it isn't quite clear to me how you'd want to use that with hierarchical clustering either. Do you define a distance aggregating the three variables such as Gower's coefficient? Oct 24, 2020 at 10:27
• Lewian, yes, it categorical. They have some other datetime parameters too :) Oct 25, 2020 at 16:49
• There's no Gower's coefficient defined.. Oct 25, 2020 at 16:49

None of them will give a meaningful result.

You attributes are not comparable. One decibel is not one eye color difference.

Results depend entirely on how you preprocess the data, and you can get pretty much any result you want (or did not want...).

Try to phrase your problem as an equation first. Do not try to solve it by trying out algorithms without a plan. You will see that your problem is not well specified, you do not know what you are solving.

If you know the number of clusters already, k-means seems more fit than hierarchical clustering, because it tries to give the best possible solution, while HC uses a greedy algorithm, it doesn't matter much if it is deterministic.

However, k-means and HC are really comparable only if you use Ward method for HC, which is really just a hierarchical version of k-means. Single linkage, for instance, can give much different results.

Also, k-means and HC are not the only alternatives, EM clustering and k-medoids are two famous non hierarchical clustering methods, that provide some variations of k-means, with iterative estimating algorithms more reliable than HC, for a fixed k.

• By Wald you probably mean Ward. "EM clustering" is not a method, you probably mean the EM algorithm for Gaussian mixtures (how to use that with eye colour??), but there are EM-algorithms also for various other models, so the term "EM clustering" doesn't say exactly what method you mean. k-means gives the "best possible solution" only according to its own objective function, which is not necessarily appropriate, particularly if separation between clusters is more important than homogeneity within clusters. Oct 24, 2020 at 10:30
• this is not a book on clustering, is an answer to the posted question. it's meant to give useful indications, not to confuse the OP, or to give her a master level understanding from scratch. Oct 24, 2020 at 10:47
• How do you use Ward with a variable such as eye colour? Oct 25, 2020 at 9:59
• jsut as the OP would most probably have: one hot encoding. that way a certain value is added to the distance between different eyed beasts, just like with Gower. you are making an issue of nothing. Oct 25, 2020 at 10:26
• stackoverflow.com/questions/56171837/… Oct 25, 2020 at 11:23