gpt4 book ai didi

python - 如何修复Python中的 'AffinityPropagation object is not callable'错误

转载 作者:太空宇宙 更新时间:2023-11-03 20:23:16 27 4
gpt4 key购买 nike

我将在 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

你不能期望输出是一个数组,来自文档示例:

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

关于python - 如何修复Python中的 'AffinityPropagation object is not callable'错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58018481/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com