我将在sklearn中使用AffinityPropagation进行群集任务,并且不断收到此错误:
“ AffinityPropagation”对象不可调用

这是代码:

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)


我希望输出的数组大小与我的输入相同!

最佳答案

通过签名,您正在使用AffinityPropagation from sklearn

您不能期望输出是一个数组,来自docs示例:

>>> 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]])

10-04 22:27