Python k-means algorithm

Eeyore picture Eeyore · Oct 9, 2009 · Viewed 88.3k times · Source

I am looking for Python implementation of k-means algorithm with examples to cluster and cache my database of coordinates.

Answer

tom10 picture tom10 · Oct 10, 2009

Update: (Eleven years after this original answer, it's probably time for an update.)

First off, are you sure you want k-means? This page gives an excellent graphical summary of some different clustering algorithms. I'd suggest that beyond the graphic, look especially at the parameters that each method requires and decide whether you can provide the required parameter (eg, k-means requires the number of clusters, but maybe you don't know that before you start clustering).

Here are some resources:

Old answer:

Scipy's clustering implementations work well, and they include a k-means implementation.

There's also scipy-cluster, which does agglomerative clustering; ths has the advantage that you don't need to decide on the number of clusters ahead of time.