JuanDi Robles
JuanDi Robles

Reputation: 3

How to find communities in a NetworkX Graph

I am trying to figure out how can I find communities in a Graph in NetworkX that depend on color and weight. I was given a code that evolves a graph from a starting state to a final state and was given the task to find the communities from the final state of it. I have been trying to do it with nx.to_dict_of_lists() and community.greedy_modularity_communities()but it did not work. As you can see in the following picture Graph in final state I have the final state of the graph and I should be getting something like:

1: [2,3]
2: [7]
3: [0]
4: [1]
5: [6]
6: [5]
7: [4]

These results should be based upon color and weight. However, by doing it with nx.to_dict_of_lists() I get the following:

{0: [1, 5, 6, 7], 
 1: [0, 2],
 2: [1, 3, 7],
 3: [2, 4, 7],
 4: [3, 5],
 5: [4, 0],
 6: [0],
 7: [3, 2, 0]} 

Also, with the community.greedy_modularity_communities() I get:

[frozenset({3, 4, 5}), frozenset({0, 1, 6}), frozenset({2, 7})]

I would really appreciate if you could help me. Thanks!

Upvotes: 0

Views: 310

Answers (0)

Related Questions