首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >两种不同的聚类方法(通过光谱分析)和两种不同的结果...怎么回事?

两种不同的聚类方法(通过光谱分析)和两种不同的结果...怎么回事?
EN

Stack Overflow用户
提问于 2019-12-24 08:52:15
回答 1查看 113关注 0票数 1

我很恼火,因为我使用了(必须的)两个等价的方法。我的目标是将一个图聚类到不同的组中。为此,一方面我“手工”计算fiedler:

代码语言:javascript
复制
import networkx as nx
import numpy.linalg as la

g1 = nx.from_numpy_matrix(A.values )
A = nx.adjacency_matrix(g1)
D = np.diag(np.ravel(np.sum(A,axis=1)))
L=D-A

l, U = la.eigh(L)
# fiedler
f = U[:,1]
labels = np.ravel(np.sign(f))
coord = nx.spring_layout(g1, iterations=100,seed=42)
fig = plt.figure(figsize=(15, 8))
nx.draw_networkx_nodes(g1, coord, node_size=25, node_color=labels, cmap = 'cool')


coord = nx.spectral_layout(g1)
fig = plt.figure(figsize=(15, 8))
nx.draw_networkx_nodes(g1, coord, node_size=25, node_color=labels, cmap = 'cool')

我得到了一个非常令人信服的光谱表示:

现在,使用这段代码(以更系统的方式):

代码语言:javascript
复制
import networkx as nx
import sklearn
clustering = sklearn.cluster.SpectralClustering(n_clusters=2,
                                                assign_labels="discretize",
                                                random_state=0)
clustering = clustering.fit(A) 
labels = clustering.labels_ 
coord = nx.spring_layout(g1, iterations=100,seed=42)
fig = plt.figure(figsize=(15, 8))
nx.draw_networkx_nodes(g1, coord,node_size=25,node_color=labels, cmap = 'cool')

我得到了一个非常糟糕的结果,看起来一点都不一样。

所以我的问题是,为什么?有人能向我解释一下我到底是如何得到不同的结果的吗?

干杯。

EN

回答 1

Stack Overflow用户

发布于 2019-12-24 22:16:46

通过调用sklearn的谱聚类,您可以使用RBF内核将您的亲和度矩阵解释为坐标。我对此并不感到惊讶,因为它工作得不好。

错误的输入->错误的输出。

试试affinity='precomputed'

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59462726

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档