Problem
A social network wants to recommend friends, and all it has is the friendship graph. Standard ML and clustering tools expect vectors, not nodes and edges. The task is to map each node to a vector that keeps the graph structure, and then find each user's social cluster. Users from the same cluster who are not yet connected become friend candidates.
Example from the article: a school social network grows beyond one school and needs a "friends" recommendation. The author demonstrates the method on an anonymized Facebook friendship graph from the Stanford Large Network Dataset Collection.
Solution in brief
Build the adjacency matrix, take its singular value decomposition (SVD), and use the first columns of the left singular matrix as node vectors. Reduce them to two dimensions with t-SNE and cluster them with DBSCAN.
Questions this case answers
- How to represent the nodes of a relationship graph as vectors that preserve graph structure, so that standard clustering and ML methods can find groups of related nodes
- How to turn the nodes of a friendship graph into vectors that ordinary clustering algorithms can use?
- How to suggest potential friends to a user of a social network from the friendship graph alone?
- How to choose how many singular vectors to keep when embedding a graph with SVD?
Tools and methods
- Adjacency matrix — an matrix of edge counts, symmetric zeros and ones for an undirected graph.
- SVD (
np.linalg.svd) — decomposition that gives the node vectors. - t-SNE (scikit-learn) — projects the vectors to 2D.
- DBSCAN (scikit-learn) — density-based clustering of the 2D points.
- NetworkX — builds the graph and the adjacency matrix.
Google or a one-time email code. No password.