我正在研究网络中的检测社区。
我使用 igraph 和 Python
对于模块化度量方面的最佳社区数量:
from igraph import *
karate = Nexus.get("karate")
cl = karate.community_fastgreedy()
cl.as_clustering().membership
为了供应所需数量的社区:
from igraph import *
karate = Nexus.get("karate")
cl = karate.community_fastgreedy()
k=2
cl.as_clustering(k).membership
不过,我喜欢使用 networkx 来做到这一点。我知道根据模块化措施获得最佳社区数量:
import community # --> http://perso.crans.org/aynaud/communities/
import fastcommunity as fg # --> https://networkx.lanl.gov/trac/ticket/245
import networkx as nx
g = nx.karate_club_graph()
partition = community.best_partition(g)
print "Louvain Modularity: ", community.modularity(partition, g)
print "Louvain Partition: ", partition
cl = fg.communityStructureNewman(g)
print "Fastgreed Modularity: ", cl[0]
print "Fastgreed Partition: ", cl[1]
但我无法获得所需的社区数量。是否有一些使用 Networkx 的算法?
我也是networkx和igraph的新手,我使用Gephi,一个数据可视化工具/软件。它具有与您现在使用的networkx中的社区检测算法相同的社区检测算法。具体来说,在http://perso.crans.org/aynaud/communities/ http://perso.crans.org/aynaud/communities/
它使用大型网络中群落的快速展开中描述的 louvain 方法,Vincent D Blondel、Jean-Loup Guillaume、Renaud Lambiotte、Renaud Lefebvre、Journal of Statistical Mechanics: Theory and Experiment 2008(10)、P10008 (12pp)
你无法获得想要的社区数量,据我所知,有两种方法值得尝试:
- 使用吉菲。您可以使用 gephi 并且有一个名为
resolution
这会改变你所获得的社区的规模。
- 使用 NetworkX。这次我们可能不会使用
best_partition(G)
不再有。但使用partition_at_level(dendrogram, level)
,我想这可能会有所帮助。
检查源代码 https://bitbucket.org/taynaud/python-louvain/src/147f0973771485ce1b45c89c1e2766f94efaa4d4/community/__init__.py?at=default点击这里了解更多信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)