Community detection in Networkx

前端 未结 2 1107
死守一世寂寞
死守一世寂寞 2021-02-07 19:14

I\'m studying about detection communities in networks.

I\'m use igraph and Python

For the optimal number of communities in terms of the modularity measure:

2条回答
  •  我寻月下人不归
    2021-02-07 19:50

    Perhaps I am misunderstanding you, but if you would like the number of communities output by the NetworkX implementation of the best_partition algorithm, just note that best_partition(G) gives a dictionary with nodes as keys and their partition number as value.

    You can count the number of unique values in a dictionary like this (likely not optimal):

    dict = {'a':1,'b':1,'c':2,'d':1,'e':3,'f':4,'g':5}
    count=list(set([i for i in dict.values()]))
    print count
    print len(count)
    

    With result

    [1, 2, 3, 4, 5]
    5
    

提交回复
热议问题