【问题标题】:Find Eigenvector centrality in python在python中查找特征向量中心性
【发布时间】:2021-09-14 18:37:40
【问题描述】:

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

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

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

我可以参考的任何解决方案、链接或任何 cmets 都会有所帮助。谢谢!

【问题讨论】:

标签: python pandas numpy networkx


【解决方案1】:

使用eigenvector_centrality functionnetworkx (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}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-20
    • 1970-01-01
    • 2020-08-04
    • 2017-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多