Clustering and community detection in social networks
Graphs exhibit clustering behavior, and identification of communities is an important task in social networks. A node's clustering coefficient is the number of triadic closures (closed triples) in the node's neighborhood. This is an expression of transitivity. Nodes with higher transitivity exhibit higher subdensity, and if completely closed, form cliques that can be identified as communities. In this recipe, we will look at clustering and community detection in social networks.
Getting ready
You will again need NetworkX and, for the first time in this chapter, the python-louvain library.
How to do it...
These steps will guide you through the detection of communities within social networks:
- Let's actually get into some clustering. The
python-louvain
library uses NetworkX to perform community detection with thelouvain
method. Here is a simple example of cluster partitioning on a small, built-in social network:
G = nx.karate_club_graph() ...