Why am I getting different community detection results for NetworkX and Gephi?

875 Views Asked by At

I've got a network with undirected, weighted edges. I'm interested in whether nodes A and B are in the same community. When I run "modularity" in Gephi, the modularity class for node A is usually, though not always, distinct from that of B. However, when I switch over to Python and run, on the exact same underlying data, either louvain_communities() (from the networkx.algorithms.community module) or community_louvain.best_partition() (from the community module), A is always in the same community as B. I've tried this at various resolutions, but keep getting similar results: the Python modules are grouping A and B significantly more often than Gephi.

My question is: What is the Gephi method doing differently? My understanding is that Gephi uses the Louvain method; the variables I can see (resolution, using weights, etc.) seem to be the same. Why the disparity?

Edit: I was asked to provide some code for this. Basically I have edge tuples with weights like so:

edge_tuples = [(A,B,5),(A,C,11),(B,C,41),…]

I have nodes as a list:

nodes = [A,B,C,…]

I use networkx to make a graph:

G = nx.Graph()
G.add_nodes_from(nodes)
G.add_weighted_edges_from(edge_tuples)

If I’m using community, I get the partition like so:

partition = community.community_louvain.best_partition(G,resolution=.7)

The resolution could be whatever, but .7 is in line with what I've tried before.

In Gephi, I'm just using ordinary node and edge tables. These are generated and exported as csv's in the process of creating the edge_tuples described above (i.e. I make them both out of the same data and just export a csv before making the networkx graph), so I don't see where the underlying data would be differing, although I'm certainly open to correction.

0

There are 0 best solutions below