亲和力繁殖Python

2022-08-06

以下示例是关于Python中包含亲和力繁殖Python用法的示例代码,想了解亲和力繁殖Python的具体用法?亲和力繁殖Python怎么用?亲和力繁殖Python使用的例子?那么可以参考以下相关源代码片段来学习它的具体使用方法。

[英]:affinity propagation python源码类型:Python
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(affinity = 'euclidean', random_state=5).fit(X)

labels = clustering.labels_ # label to each element
centers = clustering.cluster_centers_ # center of each cluster

# if you need a distance different from euclidean
# calculate your custom, pairwise distance among vectors 
# and store them into a matrix M. 
# Note: cluster_centers are no longer available

clustering = AffinityPropagation(affinity='precomputed', random_state=5).fit(M)

本文地址:https://www.itbaoku.cn/snippets/795569.html