1
ΔQ = ki,Cm − Σtot ki2m2
2
→
→
3
4
import networkx as nx
G = nx.karate_club_graph()
parts = nx.community.louvain_communities(G, weight="weight", resolution=1,
threshold=1e-07, seed=None)
Q = nx.community.modularity(G, parts)
# pip install python-louvain (github.com/taynaud/python-louvain) import community as community_louvain partition_dict = community_louvain.best_partition(G) # node -> community