我有一个使用 library(dplyr)
df %>%
select(Col1,`11`,`12`,everything())
Col1 11 12 110 1100
1 a 1 22 2 20
2 b 16 18 5 3
库的python代码
igraph
并且我需要将其转换为import igraph
edge = [(0, 6), (0, 8), (0, 115), (0, 124), (0, 289), (0, 359), (0, 363), (6, 60), (6, 115), (6, 128), (6, 129), (6, 130), (6, 131), (6, 359), (6, 529), (8, 9), (8, 17), (8, 115)]
G = igraph.Graph(edges=edge, directed=False)
G.vs['label'] = nodes
G.es["weight"] = weights
dendrogram = G.community_edge_betweenness()
clusters = dendrogram.as_clustering()
membership = clusters.membership
out = pd.Series(membership, index=nodes)
库,因为networkx
最近已停产。
igraph
但是,import networkx as nx
G = nx.Graph(edges)
dendrogram = nx.edge_betweenness_centrality(G)
clusters = nx.clustering(dendrogram)
membership = clusters.membership
out = pd.Series(membership, index=nodes)
无法群集在dendrogram
库中。有人可以帮助将networkx
代码复制到igraph
集群吗?
答案 0 :(得分:2)
问题在于“集群”是指网络科学中的两种不同事物。它要么是指聚类系数(自我图中的三角形分数; nx.clustering),要么是指一组节点(又称为数据聚类,网络社区,节点分区等)。
在这种情况下,您使用igraph community_edge_betweenness()对节点进行分层聚类,然后切割树状图以通过dendrogram.as_clustering()创建节点分区。
networkx中的等效项是使用girvan_newman:
from networkx.algorithms.community.centrality import girvan_newman
nx_dendrogram = girvan_newman(G)
move_down_dendrogram = itertools.takewhile(lambda c: len(c) <= 4, nx_dendrogram)
for c in move_down_dendrogram:
clustering_list = c
print(clustering_list)
membership = [0] * G.number_of_nodes()
for ic, cset in enumerate(clustering_list):
for n in cset:
membership[n] = ic
out = pd.Series(membership, index=nodes)