# Tuning parameters in Affinity Propagation

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))
n_cluster_list.append(n_clusters)
final_n_clusters.append(n_cluster_list)

• 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? – Romain Reboulleau Nov 17 at 21:19