Networkx中的社区检测 [英] Community detection in Networkx

查看:1092
本文介绍了Networkx中的社区检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究网络中的检测社区.

我正在使用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/

它使用大型网络中社区的快速展开,Vincent D Blondel,Jean-Loup Guillaume,Renaud Lambiotte,Renaud Lefebvre,《统计力学杂志:理论与实验》 2008(10),P10008(12pp)中描述的鲁汶方法.

您无法获得所需数量的社区,据我所知,有两种值得尝试的方法:

  • 使用Gephi.您可以使用gephi,并且有一个名为resolution的参数可以改变您获得的社区的规模.
  • 使用NetworkX.这次,我们可能不再使用best_partition(G)了.但是使用partition_at_level(dendrogram, level),我想这可能会有所帮助.

检查源代码在这里获取更多信息.

I'm studying about detection communities in networks.

I'm use igraph and Python

For the optimal number of communities in terms of the modularity measure:

from igraph import *
karate = Nexus.get("karate")
cl = karate.community_fastgreedy()
cl.as_clustering().membership

For supply the desired number of communities:

from igraph import *
karate = Nexus.get("karate")
cl = karate.community_fastgreedy()
k=2
cl.as_clustering(k).membership

However, I like to do this using networkx. I know get optimal number of communities in terms of the modularity measure:

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]

But I can not get the desired number of communities. Are there some algorithm for this, using Networkx?

解决方案

I'm also new to networkx and igraph, I used Gephi, an data visualization tool/software. And it has the same community detection algorithm as the one in networkx you are now using. Specifically, in http://perso.crans.org/aynaud/communities/

It uses the louvain method described in Fast unfolding of communities in large networks, Vincent D Blondel, Jean-Loup Guillaume, Renaud Lambiotte, Renaud Lefebvre, Journal of Statistical Mechanics: Theory and Experiment 2008(10), P10008 (12pp)

You can not get desired number of communities, as I know, there're two ways worth to try:

  • Use Gephi. You can use gephi and there's a parameter called resolution that would change the size of the community you get.
  • Use NetworkX. This time, we may not use best_partition(G) any more. But use partition_at_level(dendrogram, level) , I guess this might help.

Check the source code here for more info.

这篇关于Networkx中的社区检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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