Community detection in Networkx

本小妞迷上赌 提交于 2019-12-03 05:38:23

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.

Perhaps I am misunderstanding you, but if you would like the number of communities output by the NetworkX implementation of the best_partition algorithm, just note that best_partition(G) gives a dictionary with nodes as keys and their partition number as value.

You can count the number of unique values in a dictionary like this (likely not optimal):

dict = {'a':1,'b':1,'c':2,'d':1,'e':3,'f':4,'g':5}
count=list(set([i for i in dict.values()]))
print count
print len(count)

With result

[1, 2, 3, 4, 5]
5
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!