二分圖

Python 網路分析進階

Eric Ma

Data Carpentry instructor and author of nxviz package

二分圖

  • 將圖分成兩個集合
  • 節點只連到另一分區的節點
  • 對比:「單分圖」
Python 網路分析進階

二分圖:範例

第 1 章第 2 張圖:二分圖範例

Python 網路分析進階

NetworkX 中的二分圖

import networkx as nx
G = nx.Graph()

numbers = range(3) G.add_nodes_from(numbers, bipartite='customers')
letters = ['a', 'b'] G.add_nodes_from(letters, bipartite='products')
Python 網路分析進階

NetworkX 中的二分圖

list(G.nodes(data=True))
[(0, {'bipartite': 'customers'}),
 (1, {'bipartite': 'customers'}),
 (2, {'bipartite': 'customers'}),
 ('b', {'bipartite': 'products'}),
 ('a', {'bipartite': 'products'})]
Python 網路分析進階

度中心性

  • 定義:$$\frac{\text{number of neighbors}}{\text{number of possible neighbors}}$$
  • 可連接鄰居數取決於圖的型態
Python 網路分析進階

二分圖的中心性指標

  • 分母:使用對立分區中的節點數,而非所有其他節點

第 1 章第 2 張圖:二分圖中心性

Python 網路分析進階

篩選圖形

cust_nodes = [n for n, d in G.nodes(data=True) if  
                  d['bipartite'] == 'customers']
cust_nodes
[(0, {'bipartite': 'customers'}),
 (1, {'bipartite': 'customers'}),
 (2, {'bipartite': 'customers'})]
nx.bipartite.degree_centrality(G, cust_nodes)
{0: 0.5,
 1: 0.5,
 2: 1.0,
 'a': 0.333,
 'b': 1.0}
Python 網路分析進階

一起來練習吧!

Python 網路分析進階

Preparing Video For Download...