【问题标题】:Using scikit learn spectral clustering with precomputed affinity matrix?使用 scikit 学习具有预先计算的亲和矩阵的谱聚类?
【发布时间】:2015-06-07 11:15:06
【问题描述】:

得到一个预先计算的相似度矩阵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]))

【问题讨论】:

    标签: python-2.7 cluster-computing scikit-learn


    【解决方案1】:

    对于DBSCAN:根据documentation,默认min_samples=5。您的“集群”都没有 5 个样本,因此所有内容都被标记为噪声。 对于 SpectralClustering,如果没有更多详细信息,我无法为您提供帮助。

    【讨论】:

    • 最后一个有四个。
    • 谢谢!!有什么办法可以嗯...使用带有 dbscan 的稀疏矩阵?
    • 嗨,我读到了。我想知道的是,当预先计算的稀疏矩阵没有指定距离时,距离是多少?未指定的距离是无穷大还是零?还是应该在稀疏矩阵对象中以某种方式定义?
    • 它们被假定为零。这似乎很奇怪。但我认为稀疏输入更意味着 X 是特征,而不是相似性。
    猜你喜欢
    • 2016-03-16
    • 2017-03-02
    • 2016-01-19
    • 2014-11-13
    • 2017-12-18
    • 2016-01-03
    • 2016-02-19
    • 2013-08-25
    • 2014-08-24
    相关资源
    最近更新 更多