我正在尝试使用社区检测算法,由networkx在著名的facebook数据集上使用。这是我的密码:
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'
有什么建议吗?
发布于 2018-10-26 23:04:20
我认为您混淆了networkx中的社区模块和使用networkx的python-louvain模块中的社区检测。
如果您安装python,它的文档中的示例对我有效,并生成如下所示的映像:
请注意,您将导入community
,而不是networkx.algorithms.community
。那是,
import community
[.. code ..]
partition = community.best_partition(G_fb)
发布于 2021-08-04 16:42:41
我在CS224W上遇到了这个
AttributeError: module 'community' has no attribute 'best_partition'
请更改此文件karate.py
替换导入到import community.community_louvain as community_louvain
那对我来说很管用。
发布于 2021-07-27 19:03:43
https://stackoverflow.com/questions/53017174
复制相似问题