首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在python中查找特征向量中心性

在python中查找特征向量中心性
EN

Stack Overflow用户
提问于 2021-09-14 18:37:40
回答 1查看 107关注 0票数 1

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

代码语言:javascript
运行
复制
  from A to B weight 
   1     2     1
   3     5     1
   1     4     1
   4     1     3
   1     3     2
   6     2     1

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

任何解决方案,我可以参考的链接,或者只是任何评论都会很有帮助。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-14 18:52:13

使用networkxeigenvector_centrality function (https://networkx.org/):

代码语言:javascript
运行
复制
# 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}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69183028

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档