我现在开始使用这个界面,我有一些 Python 经验,但没什么广泛的。我正在计算一个小图的传递性和社区结构:
import networkx as nx
G = nx.read_edgelist(data, delimiter='-', nodetype=str)
nx.transitivity(G)
#find modularity
part = best_partition(G)
modularity(part, G)
然而,我得到的传递性很好 - 计算模块化时存在以下错误。
NameError: name 'best_partition' is not defined
我只是按照networkx网站提供的文档进行操作,我做错了什么吗?
据我所知best_partition
不是 networkx 的一部分。看起来你想使用https://sites.google.com/site/findcommunities/ https://sites.google.com/site/findcommunities/您可以从中安装https://bitbucket.org/taynaud/python-louvain/src https://bitbucket.org/taynaud/python-louvain/src
安装完成后community
试试这个代码:
import networkx as nx
import community
import matplotlib.pyplot as plt
G = nx.random_graphs.powerlaw_cluster_graph(300, 1, .4)
nx.transitivity(G)
#find modularity
part = community.best_partition(G)
mod = community.modularity(part,G)
#plot, color nodes using community structure
values = [part.get(node) for node in G.nodes()]
nx.draw_spring(G, cmap = plt.get_cmap('jet'), node_color = values, node_size=30, with_labels=False)
plt.show()
edit:我如何安装社区检测库
ryan@palms ~/D/taynaud-python-louvain-147f09737714> pwd
/home/ryan/Downloads/taynaud-python-louvain-147f09737714
ryan@palms ~/D/taynaud-python-louvain-147f09737714> sudo python3 setup.py install
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)