Datalens.ai
← All algorithms

GRAPH-COMMUNITIES

modularity

Returns the modularity of the given partition of the graph.

Example of usage

Identify collaboration structure with modularity 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"]}

# Quantify how well the declared departments separate collaboration ties.
groups = [{name for name, group in teams["nodes"] if group == department} for department in {x[1] for x in teams["nodes"]}]
result = nx.community.modularity(G, groups)
assert -0.5 <= result <= 1 and result > 0

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