小编ale*_*ari的帖子

Affinity Propagation首选项初始化

我需要在不事先知道集群数量的情况下执行集群.簇的数量可以是1到5,因为我可以找到所有样本属于同一实例或有限数量的组的情况.我认为亲和力传播可能是我的选择,因为我可以通过设置首选项参数来控制群集的数量.但是,如果我有人工生成的单个集群,并且我将节点之间的最小欧氏距离设置为偏好(以最小化集群数量),那么我对集群的处理非常糟糕.

"""
=================================================
Demo of affinity propagation clustering algorithm
=================================================

Reference:
Brendan J. Frey and Delbert Dueck, "Clustering by Passing Messages
Between Data Points", Science Feb. 2007

"""
print(__doc__)
import numpy as np
from sklearn.cluster import AffinityPropagation
from sklearn import metrics
from sklearn.datasets.samples_generator import make_blobs
from scipy.spatial.distance import pdist

##############################################################################
# Generate sample data
centers = [[0,0],[1,1]]
X, labels_true = make_blobs(n_samples=300, centers=centers, cluster_std=0.5,
                            random_state=0)
init = np.min(pdist(X))

##############################################################################
# Compute Affinity Propagation
af = AffinityPropagation(preference=init).fit(X)
cluster_centers_indices = af.cluster_centers_indices_
labels = …
Run Code Online (Sandbox Code Playgroud)

cluster-analysis machine-learning unsupervised-learning scikit-learn

10
推荐指数
1
解决办法
4392
查看次数