1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Network Analysis in Python

Exercise

Characterizing editing communities

You're now going to combine what you've learned about the BFS algorithm and concept of maximal cliques to visualize the network with an ArcPlot.

The largest maximal clique in the Github user collaboration network has been assigned to the subgraph G_lmc. Note that for NetworkX version 2.x and later, G.subgraph(nodelist) returns only an immutable view on the original graph. We must explicitly ask for a .copy() of the graph to obtain a mutatable version.

Instructions

100 XP
  • Go out 1 degree of separation from the clique, and add those users to the subgraph. Inside the first for loop:
    • Add nodes to G_lmc from the neighbors of G using the .add_nodes_from() and .neighbors() methods.
    • Using the .add_edges_from(), method, add edges to G_lmc between the current node and all its neighbors. To do this, you'll have create a list of tuples using the zip() function consisting of the current node and each of its neighbors. The first argument to zip() should be [node]*len(list(G.neighbors(node))), and the second argument should be the neighbors of node.
  • Record each node's degree centrality score in its node metadata.
    • Do this by assigning nx.degree_centrality(G_lmc)[n] to G_lmc.node[n]['degree centrality'] in the second for loop.
  • Visualize this network with an ArcPlot sorting the nodes by degree centrality (you can do this using the keyword argument node_order='degree centrality').