Skip to content

flowmachine.models.louvain

Source: flowmachine/models/louvain.py

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

Louvain(graph)
Source: flowmachine/models/louvain.py

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()).

Parameters

  • 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.

Examples

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(
            directed_graph=False))
Now let's run the algorithm:
l.run(weight_property='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


  1. http://barabasi.com/f/618.pdf 

  2. https://en.wikipedia.org/wiki/Modularity 

  3. https://sites.google.com/site/findcommunities/ 

  4. Vincent D. Blondel, Jean-Loup Guillaume, Renaud Lambiotte, Etienne Lefebvre. "Fast unfolding of communities in large networks". https://arxiv.org/abs/0803.0476