I've constructed a networkx DiGraph and calculated the standard "graph-level" metrics: degree centrality, betweenness centrality, eigenvector centrality, and pagerank for the entire graph. However, I'm more interested in isolating particular nodes, and looking at metrics relative to that particular node.
So the problem is as follows: given a graph G and a node X, which nodes most (directly) influence that particular node X? Presumably I have to build a subgraph H centered at X; so starting at Node X, I would "walk" the graph (say) three levels deep and use the corresponding edges to build a subgraph centered at Node X. Then I would re-run all the standard centrality metrics mentioned above on this subgraph H. Is this the best approach? Is there an efficient way of doing this in networkx? Should I try something else? What are your recommendations?
Thanks!
There is a fairly easy way to create a subgraph centered around a node. You can use networkx.ego_graph(G,n,radius) to return a subgraph of G within the specified radius of node n. There are other options for directed vs undirected, weights etc. See https://networkx.org/documentation/stable/reference/generated/networkx.generators.ego.ego_graph.html for more details.