我将在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)
我希望数组的输出大小与我输入的大小相同!
答案 0 :(得分:0)
通过签名,您正在使用AffinityPropagation from sklearn
您不能期望输出是文档示例中的数组:
>>> 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]])