属性错误:模块'网络算法。社区没有属性'BEST_PARTITION' [英] AttributeError: module 'networkx.algorithms.community' has no attribute 'best_partition'

查看:35
本文介绍了属性错误:模块'网络算法。社区没有属性'BEST_PARTITION'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,我正在尝试对著名的Facebook Snap数据集使用社区检测算法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'

有什么建议吗?

推荐答案

我认为您混淆了networkx中的community module使用networkx的python-louvain模块中的社区检测。

如果您安装了python-Louvain,则其文档中的示例对我有效,并生成类似

的图像

请注意,您将导入community,而不是networkx.algorithms.community。也就是说,

import community

[.. code ..]

partition = community.best_partition(G_fb)

这篇关于属性错误:模块'网络算法。社区没有属性'BEST_PARTITION'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆