I am doing Affinity Propagation clustering and trying to do tuning, but it takes time. A lot of time actually. As I am beginner I do not know how to get clusters. I need cluster numbers from 1 to 20 for example. Without any evaluation.

from sklearn.metrics import silhouette_samples, silhouette_score
from sklearn.cluster import AffinityPropagation

final_n_clusters = []
preference = np.arange(-1,1,0.1) # HERE
iter_value = np.arange(1,10,1)   # and HERE
iter_value = np.array(iter_value, dtype=np.int32)

for k in preference:
    n_cluster_list = []
    for j in iter_value:
        af = AffinityPropagation(preference = k, max_iter = j, affinity='precomputed').fit(X)
        labels = af.labels_
        n_clusters = len(np.unique(labels))
  • $\begingroup$ Hi, welcome to Data Science Stack Exchange! Can you please explain further what you are trying to do? It is unclear right now. Do you need to retrieve clusters, tune the model, make it work faster? $\endgroup$ – Romain Reboulleau Nov 17 at 21:19

Your Answer

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

Browse other questions tagged or ask your own question.