ZCYANG
ZCYANG

Reputation: 21

How to create a VertexClustering object in python-igraph with an finished clustering list[list] object?

I am using python-igraph to do community detection. I implemented my own community detection algorithm and the algorithm produces a list[list] object, like [[1,2,3],[4,5,6],[7,8,9]]. Now I want to know the modularity of my community detection result, and I have to transfer the list[list] object into a python-igraph VertexClustering object to use the VertexClustering.modularity function. How can I do that?

Upvotes: 2

Views: 710

Answers (1)

Hello Lili
Hello Lili

Reputation: 1587

Well, it's easier than it seems.

You just have to create a VertexClustering object providing your graph and the cluster labels as parameters:

partition = VertexClustering(g, kmeans.labels_)

plot(partition)

This implies you have to build your graph first, by adding its nodes and edges.

VertexClustering class documentation here.

I'm a little bit late, however maybe someone will find this answer useful.

Upvotes: 1

Related Questions