affinity propagation python

Solutions on MaxInterview for affinity propagation python by the best coders in the world

showing results for - "affinity propagation python"
Louisa
01 Mar 2020
1from sklearn.cluster import AffinityPropagation
2import numpy as np
3
4X = np.array([[1, 2], [1, 4], [1, 0], [4, 2], [4, 4], [4, 0]])
5clustering = AffinityPropagation(affinity = 'euclidean', random_state=5).fit(X)
6
7labels = clustering.labels_ # label to each element
8centers = clustering.cluster_centers_ # center of each cluster
9
10# if you need a distance different from euclidean
11# calculate your custom, pairwise distance among vectors 
12# and store them into a matrix M. 
13# Note: cluster_centers are no longer available
14
15clustering = AffinityPropagation(affinity='precomputed', random_state=5).fit(M)