我有一個資料框架,它是一個加權邊緣串列:
我有一個資料框架,它是一個加權邊緣串列。
from A to B weight
1 2 1
3 5 1
1 4 1
4 1 3
1 3 2
6 2 1
我想從這個加權邊緣串列中計算出特征向量中心性。
任何解決方案,我可以參考的鏈接,或任何評論都會有幫助。謝謝!
uj5u.com熱心網友回復:
使用eigenvector_centrality函式的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
源頭目標權重
0 1 2 1
1 3 5 1
2 1 4 1
3 4 1 3
4 1 3 2
5 6 2 1
# 用networkx構建圖
import networkx as nx
G = nx.from_pandas_edgelist(df, edge_attr=' weight')
# 計算每個節點的特征向量中心性,考慮到邊緣權重。
nx.eigenvector_centrality(G, weight='weight')
{1: 0.6974250778676078,
2: 0.19770984859637408,
3: 0.3954196949440728,
5: 0.10429672377035848,
4: 0.5518650949515594,
6: 0.05214836300951692}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/309466.html
標籤:
