'K-means clustering. It uses k-means++ (http://en.wikipedia.org/wiki/K-means%2B%2B) to choose the initial centroids of the clusters
Clusterizes a list of IDs (either row or cols)
:param ids: list of row (or col) ids to cluster
:param k: number of clusters
:param components: how many eigen values use (from SVD)
:param are_rows: is param *ids* a list of rows (or cols)?
:type are_rows: Boolean'

def kmeans(self, ids, k=5, components=3, are_rows=True):

    if (not isinstance(ids, list)):
        return super(SVD, self).kmeans(ids, k=k, is_row=are_rows)
    if VERBOSE:
        sys.stdout.write(('Computing    k-means,    k=%s    for    ids    %s\n' % (k, ids)))
    MAX_POINTS = 150
    points = []
    for id in ids:
        if are_rows:
            points.append(self._U.row_named(id)[:components])
        else:
            points.append(self._V.row_named(id)[:components])
    M = array(points)
    if (len(points) <= MAX_POINTS):
        centers = self._kinit(array(points), k)
        (centroids, labels) = kmeans2(M, centers, minit='matrix')
    else:
        (centroids, labels) = kmeans2(M, k, minit='random')
    i = 0
    clusters = dict()
    for cluster in labels:
        if (not clusters.has_key(cluster)):
            clusters[cluster] = dict()
            clusters[cluster]['centroid'] = centroids[cluster]
            clusters[cluster]['points'] = []
        point = self._U.row_named(ids[i])[:components]
        centroid = clusters[cluster]['centroid']
        to_centroid = self._cosine(centroid, point)
        clusters[cluster]['points'].append((ids[i], to_centroid))
        clusters[cluster]['points'].sort(key=itemgetter(1), reverse=True)
        i += 1
    return clusters
