好吧,我正在尝试在著名的 facebook 快照数据集上使用 networkx 的 社区检测算法。这是我的代码:
import networkx as nx
import matplotlib.pyplot as plt
from networkx.algorithms import community
from networkx.algorithms.community.centrality import girvan_newman
G_fb = nx.read_edgelist("./facebook_combined.txt",create_using = nx.Graph(), nodetype=int)
parts = community.best_partition(G_fb)
values = [parts.get(node) for node in G_fb.nodes()]
但是当我运行单元格时,我遇到了标题错误:
AttributeError: module 'networkx.algorithms.community' has no attribute 'best_partition'
有什么建议吗?
原文由 Mohammad Heydari 发布,翻译遵循 CC BY-SA 4.0 许可协议
我认为您将 networkx 中的 社区 模块与 使用 networkx 的 python-louvain 模块中的社区检测混淆了。
如果你安装 python-louvain,它的文档中的示例对我有用,并生成像这样的图像
请注意,您将导入
community
,而不是networkx.algorithms.community
。那是,