使用 scikit 学习具有预先计算的亲和矩阵的光谱聚类?
Using scikit learn spectral clustering with precomputed affinity matrix?
得到一个预先计算的相似度矩阵 Sim
,其中 s_ij
等于向量 i
和向量 j
之间的相似度。
正在尝试计算集群。
做
clustering = SpectralClustering(cluster_count, affinity='precomputed', eigen_solver='arpack')
clustering.fit(sparse_dok_sim_matrix)
clusters = clustering.fit_predict(sparse_dok_sim_matrix)
print clusters
我得到一些看起来像簇标签但完全错误的东西。同一簇中样本之间的边权重是图上边权重的 99%。聚类结果似乎完全随机且毫无意义。
任何建议,也许我做错了?
例如,我尝试使用 dbscan 进行此操作但一无所获:
results = block_diag(np.ones((3,3)), np.ones((3,3)), np.ones((4,4)))
results = 1000 * (np.ones((len(results), len(results))) - results)
print results
print dbscan(X=results.astype(float), metric='precomputed')
这就是结果,它说一切都是噪音,尽管很明显前三个点在同一个位置,接下来的三个点也是……最后四个也是。
[[ 0. 0. 0. 1000. 1000. 1000. 1000. 1000. 1000. 1000.]
[ 0. 0. 0. 1000. 1000. 1000. 1000. 1000. 1000. 1000.]
[ 0. 0. 0. 1000. 1000. 1000. 1000. 1000. 1000. 1000.]
[ 1000. 1000. 1000. 0. 0. 0. 1000. 1000. 1000. 1000.]
[ 1000. 1000. 1000. 0. 0. 0. 1000. 1000. 1000. 1000.]
[ 1000. 1000. 1000. 0. 0. 0. 1000. 1000. 1000. 1000.]
[ 1000. 1000. 1000. 1000. 1000. 1000. 0. 0. 0. 0.]
[ 1000. 1000. 1000. 1000. 1000. 1000. 0. 0. 0. 0.]
[ 1000. 1000. 1000. 1000. 1000. 1000. 0. 0. 0. 0.]
[ 1000. 1000. 1000. 1000. 1000. 1000. 0. 0. 0. 0.]]
(array([], dtype=int64), array([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]))
对于DBSCAN:根据documentation,默认min_samples=5
。 "clusters" 的 None 有 5 个样本,因此所有内容都标记为噪音。
对于 SpectralClustering,如果没有更多详细信息,我无法为您提供帮助。
得到一个预先计算的相似度矩阵 Sim
,其中 s_ij
等于向量 i
和向量 j
之间的相似度。
正在尝试计算集群。 做
clustering = SpectralClustering(cluster_count, affinity='precomputed', eigen_solver='arpack')
clustering.fit(sparse_dok_sim_matrix)
clusters = clustering.fit_predict(sparse_dok_sim_matrix)
print clusters
我得到一些看起来像簇标签但完全错误的东西。同一簇中样本之间的边权重是图上边权重的 99%。聚类结果似乎完全随机且毫无意义。
任何建议,也许我做错了?
例如,我尝试使用 dbscan 进行此操作但一无所获:
results = block_diag(np.ones((3,3)), np.ones((3,3)), np.ones((4,4)))
results = 1000 * (np.ones((len(results), len(results))) - results)
print results
print dbscan(X=results.astype(float), metric='precomputed')
这就是结果,它说一切都是噪音,尽管很明显前三个点在同一个位置,接下来的三个点也是……最后四个也是。
[[ 0. 0. 0. 1000. 1000. 1000. 1000. 1000. 1000. 1000.]
[ 0. 0. 0. 1000. 1000. 1000. 1000. 1000. 1000. 1000.]
[ 0. 0. 0. 1000. 1000. 1000. 1000. 1000. 1000. 1000.]
[ 1000. 1000. 1000. 0. 0. 0. 1000. 1000. 1000. 1000.]
[ 1000. 1000. 1000. 0. 0. 0. 1000. 1000. 1000. 1000.]
[ 1000. 1000. 1000. 0. 0. 0. 1000. 1000. 1000. 1000.]
[ 1000. 1000. 1000. 1000. 1000. 1000. 0. 0. 0. 0.]
[ 1000. 1000. 1000. 1000. 1000. 1000. 0. 0. 0. 0.]
[ 1000. 1000. 1000. 1000. 1000. 1000. 0. 0. 0. 0.]
[ 1000. 1000. 1000. 1000. 1000. 1000. 0. 0. 0. 0.]]
(array([], dtype=int64), array([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]))
对于DBSCAN:根据documentation,默认min_samples=5
。 "clusters" 的 None 有 5 个样本,因此所有内容都标记为噪音。
对于 SpectralClustering,如果没有更多详细信息,我无法为您提供帮助。