Creating a graph
At this point in our experiment, we have a list of users and their friends. This gives us a graph where some users are friends of other users (although not necessarily the other way around).
A graph is a set of nodes and edges. Nodes are usually objects of interest - in this case, they are our users. The edges in this initial graph indicate that user A is a friend of user B. We call this a directed graph, as the order of the nodes matters. Just because user A is a friend of user B, that doesn't imply that user B is a friend of user A. The example network below shows this, along with a user C who is friends of user B, and is friended in turn by user B as well:
In python, one of the best libraries for working with graphs, including creating, visualising and computing, is called NetworkX.
Note
Once again, you can use Anaconda to install NetworkX: conda install networkx
First, we create a directed graph using NetworkX. By convention, when importing NetworkX, we use the abbreviation...