python - iGraph 中的模块化和集群问题 [Python]

标签 python igraph modularity

我有一个图 g,其中顶点具有属性“组”。我想根据组属性来衡量图的模块化程度。以下是我的操作方法:

cl = Clustering(g.vs()['group'])
modul = g2.modularity(cl,weights=None)

集群对象 cl 如下所示:

Clustering with 134 elements and 26 clusters
[ 0] 52, 53, 54, 55, 56
[ 1] 44, 45, 46, 47
[ 2] 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105
[ 3] 73, 74, 75, 76, 77, 78
[ 4] 36, 37, 38, 39
[ 5] 3
[ 6] 85, 86, 87, 88, 89, 90, 91, 92
[ 7] 11, 48, 49, 50, 51
[ 8] 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
     120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133
[ 9] 12, 57, 58, 59, 60, 61
[10] 62, 63, 64, 65, 66
[11] 4
[12] 10, 15, 16
[13] 79, 80, 81, 82, 83, 84
[14] 0, 13, 14, 21, 22, 23, 24, 32, 33, 34, 35
[15] 28, 29, 30, 31
[16] 67, 68, 69, 70, 71, 72
[17] 1
[18] 7
[19] 19, 20
[20] 9
[21] 8
[22] 2, 40, 41, 42, 43
[23] 5
[24] 6, 17, 18
[25] 25, 26, 27 

为什么 iGraph 会引发此错误:

ValueError: iterable must yield integers

我错过了什么吗?

最佳答案

modularity 函数需要一个生成整数作为第一个参数的迭代器,而不是一个 Clustering 对象。顺便说一句,g.vs["group"] 正是为您提供了这一点,因此无需创建聚类:

g.modularity(g.vs["group"])

如果您确实想要一个Clustering对象,则需要构造一个VertexClustering,然后使用其模块化属性 (这将依次调用图形的 modularity 方法):

cl = VertexClustering(g, g.vs["group"])
cl.modularity

关于python - iGraph 中的模块化和集群问题 [Python],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33223334/

相关文章:

python - 如何正确地将 mpmath 矩阵转换为 numpy ndarray(并将 mpmath.mpf 转换为 float )

python - 将 numpy unit8 原始数组直接转换为 float32

r - igraph 中的地理布局

r - 从 R 中的 alphahull 中提取多个多边形

python - 同一站点下的多个 Django 应用程序

Python:从数据框中删除字典中不存在值的行

python - Selenium webdriver 和 unicode

c++ - igraph 中的直接选择器

modularity - Newman 模块化

ruby-on-rails - 使用 Rails 进行模块化开发