Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Community detection in Networkx

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?

like image 678
Alan Valejo Avatar asked Feb 27 '14 13:02

Alan Valejo


People also ask

What is the best community detection algorithm?

M. Girvan and M. E. J. Newman have proposed one of the most widely adopted community detection algorithms, the Girvan-Newman algorithm. According to them, groups of nodes in a network are tightly connected within communities and loosely connected between communities.

How is community detection different from clustering?

Often clustering and community detection are used interchangeably in the literature. Clustering mostly focuses on a single modality, e.g., using node attributes to group network objects, whereas community detection focuses on network structure as a function of connectivity involving social interaction.

What is community detection in data mining?

Community detection, also called graph partition, helps us to reveal the hidden relations among the nodes in the network. Many algorithms have been developed to detect communities (Clauset et al., 2004; Girvan and Newman, 2002; Lancichinetti and Fortunato, 2009).


1 Answers

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.

like image 86
zihaolucky Avatar answered Sep 22 '22 14:09

zihaolucky