如何使用归一化互信息在Python中评估igraph重叠社区

2 投票
1 回答
2979 浏览
提问于 2025-04-18 03:02

随着重叠聚类算法在社交网络分析中越来越受欢迎,我们需要一些量化的指标来衡量方法的准确性。我想知道如何在Python中使用归一化互信息(NMI,igrap中有这个功能)来评估来自igraph的重叠社区。

这个功能可以在这里找到:http://igraph.sourceforge.net/doc/python/

compare_communities(comm1, comm2, method='nmi', remove_none=False)

其中

method = "nmi"

comm1comm2 是一个重叠聚类对象(可以在这里查看:http://cneurocvs.rmki.kfki.hu/igraph/doc/python/igraph.clustering.OverlappingClustering-class.html

我尝试了这个:

cl = igraph.Clustering([(0,), (0,), (0,1), (1,), (1,), ()])

但是,它返回了这个错误:

Traceback (most recent call last):
      File "multilevel_overlapping.py", line 94, in <module>
        cl = igraph.Clustering([(0,), (0,), (0,1), (1,), (1,), ()])
      File "/usr/lib/python2.7/dist-packages/igraph/clustering.py", line 92, in __init__
        self._len = max(m for m in self._membership if m is not None)+1
TypeError: can only concatenate tuple (not "int") to tuple

我还尝试了这个:

cl = igraph.OverlappingClustering([(0,), (0,), (0,1), (1,), (1,), ()])

但是,它也返回了这个错误:

Traceback (most recent call last):
  File "multilevel_overlapping.py", line 94, in <module>
    cl = igraph.OverlappingClustering([(0,), (0,), (0,1), (1,), (1,), ()])
AttributeError: 'module' object has no attribute 'OverlappingClustering'

有没有人能帮我使用NMI函数?

1 个回答

1

文档里好像有个错别字。你提到的那个类叫做 OverlappingClustering,而不是 Clustering。所以你可以试试这个:

 cl = OverlappingClustering([(0,), (0,), (0,1), (1,), (1,), ()])

撰写回答