title: Community detection in Networkx
body: <p>I'm studying about detection communities in networks.</p>
  
  <p>I'm use igraph and Python</p>
  
  <p>For the optimal number of communities in terms of the modularity measure:</p>
  
  <pre><code>from igraph import *
  karate = Nexus.get("karate")
  cl = karate.community_fastgreedy()
  cl.as_clustering().membership
  </code></pre>
  
  <p>For supply the desired number of communities:</p>
  
  <pre><code>from igraph import *
  karate = Nexus.get("karate")
  cl = karate.community_fastgreedy()
  k=2
  cl.as_clustering(k).membership
  </code></pre>
  
  <p>However, I like to do this using networkx. I know get optimal number of communities in terms of the modularity measure:</p>
  
  <pre><code>import community # --&gt; http://perso.crans.org/aynaud/communities/
  import fastcommunity as fg # --&gt; 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]
  </code></pre>
  
  <p>But I can not get the desired number of communities. Are there some algorithm for this, using Networkx?</p>