0
votes

I try to use precomputed affinity matrix for clustering, but it doesnt work even for simple cases. I tried different dumping parameters and different values for diagonal with no success.

Below is the example.

affinities = 
    [[ 0. -1. -2. -6. -7.]
     [-1.  0. -1. -7. -8.]
     [-2. -1.  0. -8. -9.]
     [-6. -7. -8.  0. -1.]
     [-7. -8. -9. -1.  0.]]

I try to cluster the matrix using fit(..) method of sklearn Affinity Propagation module:

import sklearn.cluster
clusterer = sklearn.cluster.AffinityPropagation(affinity='precomputed', damping=0.9, verbose=True)
result = clusterer.fit(affinities)

from pprint import pprint
pprint(vars(result))

But no clusters are found (please note that result obviously should be [0,0,0,1,1]):

Converged after 23 iterations.
{'affinity': 'precomputed',
 'affinity_matrix_': array([[ 0., -1., -2., -6., -7.],
       [-1.,  0., -1., -7., -8.],
       [-2., -1.,  0., -8., -9.],
       [-6., -7., -8.,  0., -1.],
       [-7., -8., -9., -1.,  0.]]),
 'cluster_centers_indices_': array([0]),
 'convergence_iter': 15,
 'copy': True,
 'damping': 0.9,
 'labels_': array([0, 0, 0, 0, 0]),
 'max_iter': 200,
 'n_iter_': 24,
 'preference': None,
 'verbose': True}
1
Negative values for an affinity are an unusual choice, and can sometimes cause problems.Has QUIT--Anony-Mousse
So what is the preferable form of affinity matrix? Official docs for sklearn do not contain such info.UNdedss
Usually it would be a degree >= of how related objects are, e.g. the weight of a positive edge.Has QUIT--Anony-Mousse

1 Answers

1
votes

Using default value for parameter damping (0.5) should resolve the issue:

Converged after 59 iterations.
{'affinity': 'precomputed',
 'affinity_matrix_': array([[ 0., -1., -2., -6., -7.],
       [-1.,  0., -1., -7., -8.],
       [-2., -1.,  0., -8., -9.],
       [-6., -7., -8.,  0., -1.],
       [-7., -8., -9., -1.,  0.]]),
 'cluster_centers_indices_': array([1, 3]),
 'convergence_iter': 15,
 'copy': True,
 'damping': 0.5,
 'labels_': array([0, 0, 0, 1, 1]),
 'max_iter': 200,
 'n_iter_': 60,
 'preference': None,
 'verbose': True}