이분 그래프

Python 중급 네트워크 분석

Eric Ma

Data Carpentry instructor and author of nxviz package

이분 그래프

  • 두 집합으로 분할된 그래프
  • 노드는 다른 파티션의 노드에만 연결됨
  • 대비: "단일 그래프(unipartite)"
Python 중급 네트워크 분석

이분 그래프: 예시

ch1-2.007.png

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{이웃 수}}{\text{가능한 이웃 수}}$$
  • 가능한 이웃 수는 그래프 유형에 따라 달라짐
Python 중급 네트워크 분석

이분 그래프 중심성 지표

  • 분모: 전체 노드가 아닌 반대 파티션의 노드 수

ch1-2.021.png

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...