I am using sklearn affinity propagation algorithm as below.

affprop = sklearn.cluster.AffinityPropagation(affinity="precomputed", damping=0.5)

I also have a similarity matrix created for the data I am using. Now I want to use my similarity matrix to use in the affinity propagation model.

In sklearn they have different methods for this such as fit, fit_predict, predict. So, I'm not sure what to use.

Is it correct if I use,

affprop.fit(my similarity matrix)
  • $\begingroup$ For people who downvote please tell me what's wrong in this question $\endgroup$ Aug 26, 2017 at 13:36

1 Answer 1


It is correct to use as you indicated.

For example, in below , I use levenshtein for make similarity matrix. then use this matrix for clustring by affinity algorithm.

lev_similarity = -1*np.array([[distance.levenshtein(w1,w2) for w1 in words]
                              for w2 in words])

af = affprop.fit(lev_similarity)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.