社区度

    1. import community
    2. from community import community_louvain
    3. import matplotlib.pyplot as plt
    4. import networkx as nx # 画图
    5. '''社区发现'''
    6. G = nx.Graph()
    7. G.add_weighted_edges_from([
    8. (1,2,1),(1,9,1),
    9. (2,3,1),(2,5,1),(2,6,1),
    10. (3,5,1),(3,6,1),(3,9,1),
    11. (4,6,1),(4,7,1),(4,8,1),
    12. (5,6,1),(5,8,1),(7,8,1)
    13. ])
    14. partition = community_louvain.best_partition(G)
    15. print(partition)