Ala*_*ejo 13 python modularity igraph networkx
我正在研究网络中的检测社区.
我用的是igraph和Python
对于模块化度量方面的最佳社区数量:
from igraph import *
karate = Nexus.get("karate")
cl = karate.community_fastgreedy()
cl.as_clustering().membership
Run Code Online (Sandbox Code Playgroud)
为供应所需数量的社区:
from igraph import *
karate = Nexus.get("karate")
cl = karate.community_fastgreedy()
k=2
cl.as_clustering(k).membership
Run Code Online (Sandbox Code Playgroud)
但是,我喜欢使用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]
Run Code Online (Sandbox Code Playgroud)
但我无法获得所需数量的社区.使用Networkx有一些算法吗?
我也是 networkx 和 igraph 的新手,我使用了 Gephi,一种数据可视化工具/软件。它具有与您现在使用的 networkx 中相同的社区检测算法。具体来说,在http://perso.crans.org/aynaud/communities/
它使用在大型网络中社区的快速展开、Vincent D Blondel、Jean-Loup Guillaume、Renaud Lambiotte、Renaud Lefebvre、Journal of Statistical Mechanics: Theory and Experiment 2008(10)、P10008 (12pp) 中描述的 louvain 方法
您无法获得所需数量的社区,据我所知,有两种方法值得尝试:
resolution可以改变您获得的社区的规模。best_partition(G)了。但是使用partition_at_level(dendrogram, level),我想这可能会有所帮助。在此处查看源代码以获取更多信息。