I want to cluster some data points into a given number of clusters according to their nearest neighbour, but with a preference towards even sized clusters when there are multiple pairs with the same distance.
I have tried using
scipy.cluster.hierarchy behaves the same) to cluster according to the distance matrix (I have pairwise distances, but objects to cluster have no co-ordinates), but with a uniform distance matrix it merges the first two items together, then the third into the same cluster and so forth, generating one big cluster and lots of single items.
I am using a custom bit of code to parse the output matrix from
linkage and form the
k clusters. I've tried different
metric parameters, but without a strong understanding of them, and with no luck.
I am happy to consider alternative clustering methods, provided I can specify
k, need only pairwise distance/similarity, and it favours even clustering. I understand that I cannot have perfectly even clusters (nor do I want to), but I do want as even as possible distribution when things are otherwise equal.
There is a Jupyter notebook with a small example case here: https://nbviewer.jupyter.org/gist/TomAnthony/9b813d68ece7ce1f4daa394df963499c