Image by AuthorNetworks display structural patterns that reveal how relationships form and strengthen over time. Clustering measures how tightly groups of nodes interconnect, while triadic closure captures the tendency for friends of friends to become friends themselves. These patterns help you understand why communities emerge and identify nodes that bridge different groups. This tutorial extends the concepts from Network Analysis Fundamentals and complements our community detection guide by examining the structural mechanisms that create community boundaries. We’ll analyze Zachary’s Karate Club network, the same dataset used in our previous tutorials.
Prerequisites and Setup
You’ll need NetworkX installed. This tutorial assumes familiarity with basic network metrics covered in our fundamentals guide.
Load the karate club network to start exploring its structural patterns.
import networkx as nx
# Load Zachary's Karate Club network
G = nx.karate_club_graph()
print(f"Nodes: {G.number_of_nodes()}")
print(f"Edges: {G.number_of_edges()}")
Output:
Nodes: 34 Edges: 78
The network has 34 club members connected by 78 friendships, giving us plenty of structure to analyze clustering patterns.
Understanding Network-Wide Clustering
The clustering coefficient measures how often a node’s neighbors connect to each other. A high clustering coefficient means tightly knit groups where everyone knows everyone. Transitivity measures the probability that two nodes connected to a common neighbor also connect to each other. Triangles are sets of three nodes where each pair is connected, representing complete triadic closure.
avg_clustering = nx.average_clustering(G)
transitivity = nx.transitivity(G)
num_triangles = sum(nx.triangles(G).values()) // 3
print(f"Average clustering: {avg_clustering:.3f}")
print(f"Transitivity: {transitivity:.3f}")
print(f"Triangles: {num_triangles}")
Output:
Average clustering: 0.571 Transitivity: 0.256 Triangles: 45
The average clustering coefficient of 0.571 means about 57% of a node’s neighbors connect to each other. This high value suggests many tightly knit subgroups within the club. The transitivity of 0.256 means roughly one quarter of connected triads close into triangles. The network contains 45 complete triangles, showing substantial triadic closure where friends of friends have become direct friends.
Analyzing Node-Level Clustering
Different nodes show different clustering patterns. Some nodes sit within completely interconnected groups, while others bridge between separate clusters. Looking at individual clustering coefficients reveals these structural roles.
clustering = nx.clustering(G)
sorted_nodes = sorted(clustering.items(), key=lambda x: x[1], reverse=True)
for node, coef in sorted_nodes[:5]:
degree = G.degree(node)
print(f"Node {node}: {coef:.3f} (degree: {degree})")
Output:
Node 7: 1.000 (degree: 4) Node 12: 1.000 (degree: 2) Node 14: 1.000 (degree: 2) Node 15: 1.000 (degree: 2) Node 16: 1.000 (degree: 2)
Five nodes have perfect clustering coefficients of 1.000, meaning all their neighbors connect to each other. Node 7 achieves this with four connections, forming a completely interconnected group of 5 members. Nodes 12, 14, 15, and 16 each have only two connections, but those connections form complete triangles. These nodes sit within tightly cohesive subgroups where everyone knows everyone else.
Examining Triadic Closure for Specific Nodes
Triadic closure refers to the tendency for open triads (two nodes connected to a common neighbor but not to each other) to close into triangles. Analyzing triadic closure for individual nodes shows how embedded they are in tightly knit groups.
node = 0
neighbors = list(G.neighbors(node))
triangles_count = nx.triangles(G, node)
print(f"Direct connections: {len(neighbors)}")
print(f"Triangles: {triangles_count}")
print(f"Clustering: {nx.clustering(G, node):.3f}")
Output:
Direct connections: 16 Triangles: 18 Clustering: 0.150
The administrator (node 0) has 16 direct friendships and participates in 18 triangles. But the clustering coefficient of 0.150 means only 15% of possible connections among these 16 friends actually exist. This low clustering suggests the administrator connects different subgroups rather than being embedded within a single tight-knit circle. This structural position likely contributed to their influence, as they bridge multiple factions within the club.
Identifying Bridge Nodes Through Structural Holes
Nodes that connect otherwise separate groups occupy structural holes. These bridge nodes show high betweenness centrality (appearing on many shortest paths) but low clustering (their neighbors don’t connect to each other). Finding these nodes reveals who controls information flow between groups.
betweenness = nx.betweenness_centrality(G)
clustering = nx.clustering(G)
bridge_candidates = []
for node in G.nodes():
if betweenness[node] > 0.05 and clustering[node] < 0.3:
bridge_candidates.append((node, betweenness[node], clustering[node]))
for node, bet, clust in sorted(bridge_candidates, key=lambda x: x[1], reverse=True)[:5]:
print(f"Node {node}: betweenness={bet:.3f}, clustering={clust:.3f}")
Output:
Node 0: betweenness=0.438, clustering=0.150 Node 33: betweenness=0.304, clustering=0.110 Node 32: betweenness=0.145, clustering=0.197 Node 2: betweenness=0.144, clustering=0.244 Node 31: betweenness=0.138, clustering=0.200
Both leaders (nodes 0 and 33) have the highest betweenness centrality combined with the lowest clustering coefficients, confirming their roles as primary bridges between different groups. Node 0 appears on 43.8% of shortest paths while maintaining only 15% internal clustering. Node 33 appears on 30.4% of paths with 11% clustering. These structural positions gave both leaders strategic advantage in mobilizing their respective factions during the club’s split. Nodes 32, 2, and 31 also occupy bridge positions, though less prominently.

Visual showing the network with nodes colored by clustering coefficient: green (high clustering, embedded in tight groups) through yellow to red (low clustering, bridge positions), with a colorbar legend.
The color-coded visualization confirms these patterns at a glance. Nodes 0 and 33 appear in reddish-orange tones, marking them as bridge nodes with low clustering. Nodes like 7, 12, 14, 15, and 16 appear in deep green, showing their positions within completely interconnected groups. This visual makes the structural differences between embedded nodes and bridge nodes immediately obvious.
Conclusion
Clustering coefficients and triadic closure patterns reveal the structure that shapes network behavior. High clustering means cohesive subgroups where relationships reinforce each other, while low clustering combined with high betweenness identifies bridge nodes that connect separate clusters. The karate club demonstrates both patterns: some members sit within tightly knit circles with perfect triadic closure, while the two leaders occupy strategic bridge positions with low clustering but high connectivity. Understanding these structural patterns helps explain why the community detection algorithms identified the specific groupings they did, as communities form around nodes with high internal clustering separated by nodes occupying structural holes.
