Datalens.ai
← All algorithms

GRAPH-COMMUNITIES

louvain_communities

Find the best partition of a graph using the Louvain Community Detection.

Example of usage

Identify collaboration structure with louvain_communities in a six-person, two-department organization.

Usage / limitations

+Use when: Explore employee collaboration patterns, densely connected teams and cross-team bridging.

−Limitations: Results depend on graph topology, edge completeness and algorithm assumptions; small networks are illustrative.

Mathematical formula

See method documentation: implementation and assumptions vary.
Sample dataShow
{
  "variable": "teams",
  "domain": "Cross-team collaboration network",
  "feature_names": [
    "team",
    "department"
  ],
  "nodes": [
    [
      "Ana",
      "Design"
    ],
    [
      "Ben",
      "Design"
    ],
    [
      "Cara",
      "Design"
    ],
    [
      "Dan",
      "Engineering"
    ],
    [
      "Eva",
      "Engineering"
    ],
    [
      "Finn",
      "Engineering"
    ]
  ],
  "edges": [
    [
      "Ana",
      "Ben"
    ],
    [
      "Ben",
      "Cara"
    ],
    [
      "Cara",
      "Ana"
    ],
    [
      "Dan",
      "Eva"
    ],
    [
      "Eva",
      "Finn"
    ],
    [
      "Finn",
      "Dan"
    ],
    [
      "Cara",
      "Dan"
    ]
  ]
}

Code example (Python)

# DataLens.ai example — cross-team collaboration analysis.
# The named teams input is provided by Copy input + code + test.
import networkx as nx

# Convert employee collaboration links into an undirected graph.
G = nx.Graph()
G.add_nodes_from([row[0] for row in teams["nodes"]])
G.add_edges_from(teams["edges"])
# Associate each employee with their declared department.
departments = {name: group for name, group in teams["nodes"]}

# Optimise community modularity using the Louvain procedure.
result = nx.community.louvain_communities(G, seed=7)
assert len(result) >= 2 and set().union(*map(set, result)) == set(G)

# Assertions above validate this graph result.
print("Expected output verified")