AttributeError:模块“networkx.algorithms.community”没有属性“best_partition”

2024-01-01

好吧,我正在尝试使用社区检测算法 by networkx在著名的 Facebook snap 数据集上。 这是我的代码:

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'

有什么建议吗?


我认为你混淆了社区模块 https://networkx.github.io/documentation/stable/reference/algorithms/community.html在networkx中适当的社区检测python-louvain https://python-louvain.readthedocs.io/en/latest/模块哪个uses网络x。

如果您安装 python-louvain,其文档中的示例对我有用,并生成类似的图像

请注意,您将导入community, not networkx.algorithms.community。那是,

import community

[.. code ..]

partition = community.best_partition(G_fb)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

AttributeError:模块“networkx.algorithms.community”没有属性“best_partition” 的相关文章

随机推荐