I've a list of binary strings and I'd like to cluster them in Python, using Hamming distance as metric. I also would like to set the number of centroids (i.e. clusters) to create.

Which algorithm do you suggest?

  • $\begingroup$ you can use k-nearestneighbours, with metric as the hamming distance. a simple google search yielded this result, saedsayad.com/k_nearest_neighbors.htm $\endgroup$ – Josyula Krishna Sep 5 '18 at 13:03
  • $\begingroup$ Yeah, there are lot of algorithms. The problem is if their Python implementation works correctly on strings, hence the question. $\endgroup$ – 4ndrew Sep 5 '18 at 13:24
  • $\begingroup$ Not an answer to the question but I would opt for a Bernoulli Mixture model in this case. $\endgroup$ – degenerate hessian Sep 5 '18 at 14:15
  • $\begingroup$ @JosyulaKrishna k nearest neighbors is not a clustering algorithm. $\endgroup$ – Has QUIT--Anony-Mousse Sep 10 '18 at 20:39
  • $\begingroup$ @Anony-Mousse thanks for the correction, you are right. apologies. $\endgroup$ – Josyula Krishna Sep 16 '18 at 10:14

The obvious first thing to try is hierarchical clustering.

Because it can use an arbitrary distance matrix.

Why don't you just try some? That's faster than asking on a web site...

  • $\begingroup$ Indeed I've tried some, like Affinity propagation - in which I can't (don't know how to ) set a fixed number of centroids - or k-medoids (which actually works). Now I've asked here in order to find more solutions. Agglomerative Clustering is a hierarchical clustering algorithm supplied by scikit, but I don't know how to give strings as input, since it accepts couple (x,y) as elements, if I'm not wrong. $\endgroup$ – 4ndrew Sep 11 '18 at 16:36
  • $\begingroup$ You can also give a distance matrix, as you probably did for affinity propagation. See the documentation. $\endgroup$ – Has QUIT--Anony-Mousse Sep 11 '18 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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