如何在PythoniGraph中使用完成的集群列表[list]对象创建VertexClustering对象?

如何在PythoniGraph中使用完成的集群列表[list]对象创建VertexClustering对象?,python,graph,igraph,Python,Graph,Igraph,我正在使用pythonigraph进行社区检测。我实现了我自己的社区检测算法,该算法生成一个list[list]对象,如[[1,2,3]、[4,5,6]、[7,8,9]]。现在我想知道我的社区检测结果的模块性,我必须将list[list]对象转换为python igraph VertexClustering对象,以使用VertexClustering.modularity函数。我该怎么做呢?嗯,这比看起来容易 您只需创建一个VertexExclustering对象,将图形和簇标签作为参数提供:

我正在使用pythonigraph进行社区检测。我实现了我自己的社区检测算法,该算法生成一个list[list]对象,如[[1,2,3]、[4,5,6]、[7,8,9]]。现在我想知道我的社区检测结果的模块性,我必须将list[list]对象转换为python igraph VertexClustering对象,以使用VertexClustering.modularity函数。我该怎么做呢?

嗯,这比看起来容易

您只需创建一个VertexExclustering对象,将图形和簇标签作为参数提供:

partition = VertexClustering(g, kmeans.labels_)

plot(partition)
这意味着您必须首先通过添加节点和边来构建图形

VertexClustering类文档

我有点晚了,不过也许有人会发现这个答案很有用