简体   繁体   中英

How to fix 'AffinityPropagation object is not callable' error in Python

I am going to do a clustering task with AffinityPropagation in sklearn and I keep getting this error: 'AffinityPropagation' object is not callable

Here is the code:

from sklearn.cluster import AffinityPropagation
x = stacked_codes.detach().numpy()
AP =AffinityPropagation(affinity='euclidean', convergence_iter=15, copy=True, damping=0.5, max_iter=1000, preference=None, verbose=False)
AP.fit(x)

I expect the output of an array of the same size as my input!

by signature, you are using AffinityPropagation from sklearn

you can't expect that the output to be an array, from docs example:

>>> from sklearn.cluster import AffinityPropagation
>>> import numpy as np
>>> X = np.array([[1, 2], [1, 4], [1, 0],
...               [4, 2], [4, 4], [4, 0]])
>>> clustering = AffinityPropagation().fit(X)
>>> clustering 
AffinityPropagation(affinity='euclidean', convergence_iter=15, copy=True,
          damping=0.5, max_iter=200, preference=None, verbose=False)
>>> clustering.labels_
array([0, 0, 0, 1, 1, 1])
>>> clustering.predict([[0, 0], [4, 4]])
array([0, 1])
>>> clustering.cluster_centers_
array([[1, 2],
       [4, 2]])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM