sklearn.cluster.affinity_propagation?

sklearn.cluster.affinity_propagation(S, *, preference=None, convergence_iter=15, max_iter=200, damping=0.5, copy=True, verbose=False, return_n_iter=False, random_state='warn')

[源碼]

執行數據的親和傳播聚類

用戶指南中閱讀更多內容

參數 說明
S array-like, shape (n_samples, n_samples)
點之間的相似矩陣
preference array-like, shape (n_samples,) or float, optional
每個點的偏好值越大,就越有可能被選擇作為樣本。樣本數,即聚類的樣本數,受輸入偏好值的影響。如果首選項不是作為參數傳遞,則它們將被設置為輸入相似點的中位數(從而導致適度的聚類數目)。對于較小數量的簇,可以將其設置為相似性的最小值。
convergence_iter int, optional, default: 15
停止收斂的估計簇數目不變的迭代次數
max_iter int, optional, default: 200
最大迭代次數
damping float, optional, default: 0.5
阻尼系數在0.5到1之間。
copy boolean, optional, default: True
如果copy是False,則通過該算法對親和矩陣進行修改,以提高內存效率。
verbose boolean, optional, default: False
詳細程度
return_n_iter bool, default False
是否返回迭代次數
random_state int or np.random.RandomStateInstance, default: 0
偽隨機數發生器控制起動狀態。對跨函數調用的可重復結果使用整數。見Glossary
返回值 說明
cluster_centers_indices array, shape (n_clusters,)
簇中心指數
labels array, shape (n_samples,)
每個點的聚類標簽
n_iter int
運行的迭代數。只有當return_n_iter設置為True時才返回。

舉個例子,參見examples/cluster/plot_affinity_propagation.py.

當算法不收斂時,為每個訓練樣本返回一個空數組作為cluster_center_indices, -1作為標簽。

當所有訓練樣本具有相同的相似性和相同的偏好時,聚類中心和標簽的分配取決于偏好。如果偏好小于相似性,則將返回每個樣本的單個中心聚類和標簽0。否則,每個訓練樣本都會成為自己的聚類中心,并被分配一個唯一的標簽。

參考

Brendan J. Frey and Delbert Dueck, “Clustering by Passing Messages Between Data Points”, Science Feb. 2007

sklearn.cluster.affinity_propagation使用示例?