Let's say I study up to 10 clusters, with scipy I usually generate a “elbow” graph as follows:
from scipy import cluster
cluster_array = [cluster.vq.kmeans(my_matrix, i) for i in range(1,10)]
pyplot.plot([var for (cent,var) in cluster_array])
pyplot.show()
Since then, I was motivated to use sklearn for clustering, but I'm not sure how to create the array needed to build, as in the scipy case. My best guess:
from sklearn.cluster import KMeans
km = [KMeans(n_clusters=i) for i range(1,10)]
cluster_array = [km[i].fit(my_matrix)]
Unfortunately, this led to an invalid command error. What is the best sklearn way to do this?
thank
source
share