vtraag/leidenalg

Modularity (Q value) for each cluster

sgautam666 opened this issue · 3 comments

It seems like the current partition method can return modularity for the cluster result. Is it possible to get the Q-value to each individual clusters?

No, no such values per community are returned. But you can easily calculate this yourself using standard python and functionality of igraph. If you are not able to figure it out, let me know.

It would be nice if you have an example already that you can share. Thank you

Sure, here's an example of how to calculate some statistics per cluster

#%% Create graph

G = ig.Graph.Famous('Zachary')

#%% Run clustering

resolution = 0.05
part = la.find_partition(G, la.CPMVertexPartition, 
                         resolution_parameter=resolution)

#%% Calculate statistics per cluster

Qc = []
for H in part.subgraphs():
    ec = H.ecount()
    nc = H.vcount()
    Qc.append(2*ec - resolution*nc*(nc - 1))
    print(e, nc, Qc)

print(sum(Qc), part.quality())