Skip to content


Source: flowmachine/models/

The Louvain Method is a popular community identification algorithm for the exploration of very large networks. The algorithm 4 was designed to optimize for the network's Modularity. 2 That is, this algorithm measures the density of connections (i.e. edges) from nodes and identifies "small" communities. Then it uses those "small" to identify the interactions that they have with other communities of comparable size. It does so iteratively until "a maximum of modularity is attained". 1 3

Class Louvain

Source: flowmachine/models/

Class for running the Louvain community identifying on a networkx Graph(). This class is useful for quickly identifying communities from a calculated flowmachine feature (e.g. ContactBalance()).


  • graph: networkx.Graph() object

    This parameter specifies a networkx.Graph() object to use. This can be a flowmachine feature (e.g. ContactBalance()) after calling the to_networkx() method.


The class needs to be instantiated with a networkx.Graph(). One can use classes that have the GraphMixin mixin as follows:

l = Louvain(
        flowmachine.features.ContactBalance('2016-01-02', '2016-01-07').to_networkx(
Now let's run the algorithm:'events', min_members=9)
                 subscriber  community
0    bvEWVnZdwJ8Lgkm2          0
1    YMBqRkzbbxGkX3zA          0
2    7XebRKr35JMJnq8A          1
3    xE8QMJxmLGMW6lZ4          1
4    w2YgmOPlr2O5x3VJ          2
5    NBpb54xVMEw1Yqza          2
6    7lNP0mDOAK3xKWv4          3




  4. Vincent D. Blondel, Jean-Loup Guillaume, Renaud Lambiotte, Etienne Lefebvre. "Fast unfolding of communities in large networks".