GNN学习(一):基础知识

 1 # !usr/bin/env python
 2 # -*- coding:utf-8 _*-
 3 # @Time  :2022/8/20 10:46
 4 # @Author: VVZ
 5 # @File  :1.2.py
 6 
 7 
 8 import numpy as np
 9 import pandas as pd
10 import networkx as nx
11 
12 edges = pd.DataFrame()
13 edges['sources'] = [1,1,1,2,2,3,3,4,4,5,5,5] # 起始节点
14 edges['targets'] = [2,4,5,3,1,2,5,1,5,1,3,4] # 终止节点
15 edges['weights'] = [1,1,1,1,1,1,1,1,1,1,1,1]
16 
17 G = nx.from_pandas_edgelist(edges, source='sources', target='targets', edge_attr='weights')
18 # degree
19 print('degree:', nx.degree(G))
20 # 连通分量
21 print('连通分量:', list(nx.connected_components(G)))
22 # 图直径
23 print('图直径:', nx.diameter(G))
24 # 度中心性
25 print('度中心性:', nx.degree_centrality(G))
26 # 特征向量中心性
27 print('特征向量中心性:',nx.eigenvector_centrality(G))
28 # betweenness
29 print('betweenness:', nx.betweenness_centrality(G))
30 # clossness
31 print('clossness:', nx.closeness_centrality(G))
32 # pagerank
33 print('pagerank:', nx.pagerank(G))
34 # HITS
35 print('HITS:', nx.hits(G))

来自b站视频学习

posted @ 2022-08-20 10:50  vv_869  阅读(44)  评论(0编辑  收藏  举报