【问题标题】:Different result of community detection function in igraph R and Pythonigraph R和Python中社区检测功能的不同结果
【发布时间】:2016-05-22 08:42:28
【问题描述】:

我在大型网络中检测到社区,并且 igraph Python 的模块化程度很低。我怀疑结果。所以我在 igraph R 中再次尝试。模块化要高得多。我不知道原因。下面,我将编写一个示例网络和我使用的代码。

graph:(ncol格式。图是无向的。第三列是权重。)

1 2 123
1 3 32
2 3 523
3 6 3
6 5 11
6 8 234
5 8 324
3 9 234
9 11 32
9 12 5534
9 13 32
11 12 322
11 13 3
12 13 32

R 代码:

library(igraph)
g=read.graph('graph.ncol',format='ncol',directed=F)
c=multilevel.community(g)
modularity(c)
[1] 0.2845496

Python 代码:

import igraph
g=igraph.Graph.Read_Ncol('graph.ncol',directed=False)
c=g.community_multilevel()
c.modularity
0.4974489795918367

在我原来的网络中,使用 R 和 Python 的社区数量有很大不同。它不仅是多级方法。我也尝试过 fastgreedy 方法。使用 R 和 Python 的结果也不同。

【问题讨论】:

    标签: python r igraph modularity


    【解决方案1】:

    R 接口在计算社区结构和模块化时会自动使用来自weight 属性的权重,而 Python 接口则不会。例如,在 Python 中:

    >>> g=load("test.ncol", directed=False)
    >>> g.multilevel_community().q
    0.4974489795918367
    >>> g.multilevel_community(weights=g.es["weight"]).q
    0.2845496103894415
    

    【讨论】:

    • 谢谢!我应该小心使用 igraph Python。
    猜你喜欢
    • 2016-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-16
    • 2020-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多