Community detection in social networks using brute-force method
We are going to divide the nodes of the graph into two or more communities using the brute force method. The brute force method means we will try every division of nodes into communities and check whether the communities are correctly divided or not. We will use a brute force method for this task.
- Create a graph of N nodes and its edges or take an inbuilt graph like a barbell graph.
- Now take two lists as FirstCommunity and SecondCommunity.
- Now start putting nodes into communities like put 1st node in FirstCommunity and rest N-1 nodes to SecondCommunity and check its inter and intra edges.
- Now we will make combinations using itertools.
- Repeat steps 3 and 4 for every combination.
- Now check which division is best by taking the ratio of intra/number of inter-community edges.
- Now find the value of FirstCommunity and SecondCommunity with maximum ratio and print that value.
Below is the implementation.
[ [0,1,2,3,4] ] , [ [8,9,5,6,7] ]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course