0

I'm working on network analysis and I'm new to python. I want to find out the centrality of every node within a cluster using i graph and python pandas.

I have tried the following:

Creating a graph:

tuples = [tuple(x) for x in data.values]
g=igraph.Graph.TupleList(tuples, directed = False,weights=True)

community detection using fast greedy algorithm:

fm = g.community_fastgreedy()
fm1 = fm.as_clustering()

clusters like this are formed:

[1549] 96650006, 966543799, 966500080
[1401] 96650006, 966567865, 966500069, 966500071

Now, I would like to get the eigenvalue centrality for each number within a cluster, so that i know which is the most important number within a cluster.

dennlinger
  • 9,890
  • 1
  • 42
  • 63
SAM
  • 9
  • 1

1 Answers1

0

I am not very familiar with the eigenvector centrality in igraph, but here is the following solution I came up with:

# initial code is the same as yours
import numpy as np
# iterate over all created subgraphs created:
for subgraph in fm1.subgraphs():
    # this is basically already what you want
    cents = subgraph.eigenvector_centrality() 
    # get additionally the index of the respective vector
    max_idx = np.argmax(cents)
    print(subgraph.vs[max_idx]) # gets the correct vertex element.

Essentially, you want to utilize the option to access the created clusters as a graph (.subgraphs() allows you to do exactly that). The rest is then "just" simple manipulation of the graph object to get the element with the respective maximum eigenvector centrality.

dennlinger
  • 9,890
  • 1
  • 42
  • 63