在 python 中找到特征向量中心性

Find Eigenvector centrality in python

我有一个数据框,它是一个加权边列表:

  from A to B weight 
   1     2     1
   3     5     1
   1     4     1
   4     1     3
   1     3     2
   6     2     1

我正在尝试从这个加权边列表计算特征向量中心性。

任何解决方案,link 我可以参考,或者任何评论都会有所帮助。谢谢!

使用 eigenvector_centrality function of networkx (https://networkx.org/):

# Create example DataFrame
df = pd.DataFrame({'source': [1, 3, 1, 4, 1, 6],
                   'target': [2, 5, 4, 1, 3, 2],
                   'weight': [1, 1, 1, 3, 2, 1]})
df
   source  target  weight
0       1       2       1
1       3       5       1
2       1       4       1
3       4       1       3
4       1       3       2
5       6       2       1

# Build graph with networkx
import networkx as nx
G = nx.from_pandas_edgelist(df, edge_attr='weight')

# Compute eigenvector centrality of each node, accounting for edge weights
nx.eigenvector_centrality(G, weight='weight')

{1: 0.6974250778676078,
 2: 0.19770984859637408,
 3: 0.3954196949440728,
 5: 0.10429672377035848,
 4: 0.5518650949515594,
 6: 0.05214836300951692}