Многие методы кластеризации, включая scipy.cluster
, начинаются с сортировки всех парных расстояний,
~ 60 миллионов в вашем случае, не слишком большое.
Сколько времени займет у вас следующее?
import scipy.cluster.hierarchy as hier
import pylab as pl
def fcluster( pts, ncluster, method="average", criterion="maxclust" ):
""" -> (pts, Y pdist, Z linkage, T fcluster, clusterlists)
ncluster = n1 + n2 + ... (including n1 singletons)
av cluster size = len(pts) / ncluster
"""
pts = np.asarray(pts)
Y = scipy.spatial.distance.pdist( pts ) # ~ N^2 / 2
Z = hier.linkage( Y, method ) # N-1
T = hier.fcluster( Z, ncluster, criterion=criterion )
# clusters = clusterlists(T)
return (pts, Y, Z, T)
hier.dendrogram( Z )
Как переставить матрицу и сюжет красиво спросили
здесь
Так в марте с частичным ответом.