【发布时间】:2019-10-04 03:39:36
【问题描述】:
参考:https://stackoverflow.com/a/44907357/305883
我正在使用 python-louvain 实现来检测完整加权图中的社区。p>
但我只得到一个分区,包含所有节点。
代码:
import community # this is pip install python-louvain
import networkx as nx
import matplotlib.pyplot as plt
# Replace this with your networkx graph loading depending on your format !
# using graph g as a completed graph, weights between 0 and 1
#first compute the best partition
partition = community.best_partition(g)
#drawing
size = float(len(set(partition.values())))
pos = nx.spring_layout(g)
count = 0.
for com in set(partition.values()) :
count = count + 1.
list_nodes = [nodes for nodes in partition.keys() if partition[nodes] == com]
nx.draw_networkx_nodes(g, pos, list_nodes, node_size = 20, node_color = str(count / size))
nx.draw_networkx_edges(g, pos, alpha=0.1)
plt.show()
我想从一个完整的加权网络中提取社区。p>
我也尝试了 girvan_newman (https://networkx.github.io/documentation/networkx-2.0/reference/algorithms/generated/networkx.algorithms.community.centrality.girvan_newman.html),但只能从 200 个节点(包括 198 个节点和 2 个节点)的完整图中检测到 2 个社区。p>
Louvain 是否可以正常工作以检测完整图中的社区? 更好的建议?
【问题讨论】:
-
您确定您的权重在图表中的键
weight之下吗?如果您在未加权的完整图上执行 Louvain,它在逻辑上会返回一个集群。
标签: python-3.x graph cluster-analysis networkx