<p>A (very) partial answer (and solution) to your question is to use <a href="https://arxiv.org/pdf/1703.09307.pdf" rel="nofollow noreferrer">Fluid Communities algorithm</a> implemented by Networkx as <a href="https://networkx.github.io/documentation/stable/reference/algorithms/generated/networkx.algorithms.community.asyn_fluid.asyn_fluidc.html#networkx.algorithms.community.asyn_fluid.asyn_fluidc" rel="nofollow noreferrer"><code>asyn_fluidc</code></a>.</p>

<p>Note that it works on connected, undirected, unweighted graphs, so if your graph has n connected components, you should run it n times. In fact this could be a significant issue as you should have some sort of preliminary knowledge of each component to choose the corresponding k.</p>

<p>Anyway, it is worth a try.</p>
Community Detection Algorithms using NetworkX
<p>I have a network that is a graph network and it is the Email-Eu network that is available in <a href="https://snap.stanford.edu/data/email-Eu-core.html" rel="nofollow noreferrer">here</a>.</p>

<p>This dataset has the actual dataset, which is a graph of around 1005 nodes with the edges that form this giant graph. It also has the ground truth labels for the nodes and its corresponding communities (department). Each one of these nodes belongs to one of each 42 departments.</p>

<p>I want to run a community detection algorithm on the graph to find to the corresponding department for each node. My main objective is to find the nodes in the largest community.</p>

<p>So, first I need to find the first 42 departments (Communities), then find the nodes in the biggest one of them.</p>

<p>I started with Girvan-Newman Algorithm to find the communities. The beauty of Girvan-Newman is that it is easy to implement since every time I need to find the edge with the highest betweenness and remove it till I find the 42 departments(Communities) I want.</p>

<p>I am struggling to find other Community Detection Algorithms that give me the option of specifying how many communities/partitions I need to break down my graph into.</p>

<p>Is there any Community Detection Function/Technique that I can use, which gives me the option of specifying how many communities do I need to uncover from my graph? Any ideas are very much appreciated.</p>

<p>I am using Python and NetworkX.</p>