1
\$\begingroup\$

I was using facebook dataset and making a graph on it. But was not been able to find different groups/communities in it. The code was using is this:

import networkx as nx
import matplotlib.pyplot as plt

g = nx.read_edgelist('facebook_combined.txt', create_using=nx.Graph(), nodetype=int)
print nx.info(g)

sp = nx.spring_layout(g)
nx.draw_networkx(g, pos=sp, with_labels=False, node_size=35)
# plt.axes('off')
plt.show()

The result i was getting is this: enter image description here

But was not been able to find groups or communities in it.

The link to the dataset is here

The source to the is here

\$\endgroup\$
0
\$\begingroup\$

After searching and researching to find the solution to this question i came up with this answer:

To find/detect communities in facebook snap dataset:

import networkx as nx
import matplotlib.pyplot as plt
import community


'''Exploratory Data Analysis'''
g = nx.read_edgelist('facebook_combined.txt', create_using=nx.Graph(), nodetype=int)
print nx.info(g)

'''Simple Graph'''
# sp = nx.spring_layout(g)
# nx.draw_networkx(g, pos=sp, with_labels=False, node_size=35)
# # plt.axes("off")
# plt.show()

'''Graph with communities dectection'''
spring_pos = nx.spring_layout(g)
parts = community.best_partition(g)
values = [parts.get(node) for node in g.nodes()]

plt.axis("off")
nx.draw_networkx(g, pos=spring_pos, cmap=plt.get_cmap("jet"), node_color=values, node_size=35, with_labels=False)
plt.show()

this will give the following output:

enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.