igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] walktrap membership help


From: Tamás Nepusz
Subject: Re: [igraph] walktrap membership help
Date: Thu, 15 Nov 2012 13:25:28 +0100

Hi,

> I just started out with iGraph in the python interface, I have trouble 
> printing out the membership of the community_walktrap.
The walktrap method does not give you a membership vector, it gives you a 
dendrogram instead (since it is a hierarchical clustering method). You must 
"cut" the dendrogram somewhere in order to obtain a membership vector. The 
easiest way to do this is to cut the dendrogram at the point where the 
modularity is maximal, and luckily the VertexDendrogram class has a method for 
that:

dendrogram = g.community_walktrap()
cl = dendrogram.as_clustering()
print cl.membership

(Note that "membership" is a property and not a method, so you don't need () at 
the end).

> After this I want to add this membership as an attribute to the respective 
> vertex, like this:
> g.vs["community"] = 0 (but this of course for each vertex).
That's easy: g.vs["community"] = cl.membership

Best,
Tamas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]