Implementing DeepWalk
Now that we have a good understanding of every component in this architecture, let’s use it to solve an ML problem.
The dataset we will use is Zachary’s Karate Club. It simply represents the relationships within a karate club studied by Wayne W. Zachary in the 1970s. It is a kind of social network where every node is a member, and members who interact outside the club are connected.
In this example, the club is divided into two groups: we would like to assign the right group to every member (node classification) just by looking at their connections:
- Let’s import the dataset using
nx.karate_club_graph()
:G = nx.karate_club_graph()
- Next, we need to convert string class labels into numerical values (Mr. Hi =
0
,Officer
=1
):labels = [] for node in G.nodes: label = G.nodes[node]['club'] labels.append(1 if label == 'Officer' else 0)
- Let’s plot this graph...