A tutorial demonstrating techniques to visualize our Facebook networks using the Facebook API and Python.
Generate the network graph
- Download the code from the GitHub repo. Unzip.
Download your network data from the Facebook API.
-‘Personal network’ -> start -> click ‘gdf’ and Save as…
- Put this data inside the unzipped folder from GitHub.
- On command line, go inside the InteractiveVis folder.
Make script ‘setup.sh’ executable:
chmod u+x setup.sh
Run the GitHub script to install dependencies:
-This installs numpy, networkx, and pyparsing. It’s important that the networkx installed in your Python is version 1.8.1.
Run the Python script to load data, detect communities, and layout nodes:
Load up a local server:
python -m SimpleHTTPServer
- On Firefox, go to: http://localhost:8000/network/?config=config_fb.json/
Analyze the network graph
Import the NetworkX library into Python:
import networkx as nx
Import the Counter object:
from collections import Counter
Import graph data into Python:
G = nx.read_gml('facebook.gml')
This will allow you to export the nodes in a useable format, for example:
cent = nx.degree_centrality(G) cent = Counter(cent) cent.most_common(10)
-These functions combined will output the 10 most connected nodes in the graph. There are many other centrality measures, see the documentation for NetworkX