I calculate betweenness centrality for the Florentine Families Graph by:
import networkx as nx
# build up a graph
G = nx.florentine_families_graph()
bw_centrality = nx.betweenness_centrality(G, normalized=False)
Excerpt from the description of betweenness_centrality(...) in networkx,
Betweenness centrality of a node v is the sum of the fraction of all-pairs shortest paths that pass through v:
Therefore, betweenness centrality should be less than 1. However, I got the result: (the betweenness centrality of the red node, 'Medici', is 47.5)
The way I calculate the betweenness centrality is as follows,
node_and_times = dict.fromkeys(G.nodes(), 0) # a dict of node : the number of shortest path passing through node
sum_paths = 0
for s, t in itertools.product(G.nodes(), repeat=2): # all pair of nodes <s, t>
paths = nx.all_shortest_paths(G, s, t) # generator of lists
for path in paths:
sum_paths += 1
# stats nodes passing through shortest path
for node in path[1:-1]: # intermediate nodes
node_and_times[node] += 1
bw_centrality = {k : v*1.0/sum_paths for k, v in node_and_times.items()}
and I got the following result,
Am I right?
As mentioned by the answerers, removing normalized=False got the following result which is not consistent with my calculation.





the number of shortest paths passing through vtothe total number of shortest paths. - SparkAndShine