투영 개념

Python 중급 네트워크 분석

Eric Ma

Data Carpentry instructor and author of nxviz package

투영

  • 한 파티션의 노드들 간 관계를 탐색할 때 유용함
    • 다른 파티션과의 연결을 조건으로 함
Python 중급 네트워크 분석

투영

  • 이분 연결성을 단일 파티션으로 표현

ch2-1.006.png

Python 중급 네트워크 분석

투영

  • 이분 연결성을 단일 파티션으로 표현

ch2-1.007.png

Python 중급 네트워크 분석

투영

  • 이분 연결성을 단일 파티션으로 표현

ch2-1.008.png

Python 중급 네트워크 분석

투영

  • 이분 연결성을 단일 파티션으로 표현

ch2-1.009.png

Python 중급 네트워크 분석

디스크의 그래프

  • 평면 에지 리스트
  • CSV 파일: 노드 목록 + 메타데이터, 에지 목록 + 메타데이터
Python 중급 네트워크 분석

네트워크 데이터 읽기

import networkx as nx
G = nx.read_edgelist('american-revolution.txt')

list(G.edges(data=True))[0:5]
[('Parkman.Elias', 'LondonEnemies', {'weight': 1}),
 ('Parkman.Elias', 'NorthCaucus', {'weight': 1}),
 ('Inglish.Alexander', 'StAndrewsLodge', {'weight': 1}),
 ('NorthCaucus', 'Chadwell.Mr', {'weight': 1}),
 ('NorthCaucus', 'Pearce.IsaacJun', {'weight': 1})]
  • 텍스트 파일
    Barrett.Samuel LondonEnemies {'weight': 1}
    Barrett.Samuel StAndrewsLodge {'weight': 1}
    Marshall.Thomas LondonEnemies {'weight': 1}
    Eaton.Joseph TeaParty {'weight': 1}
    Bass.Henry LondonEnemies {'weight': 1}
    
Python 중급 네트워크 분석

이분 그래프 투영

list(G.nodes())
['product2', 'customer3', 'customer1', 'product3',  
    'customer2', 'product1']
list(G.edges())
[('product2', 'customer1'),
 ('product2', 'customer2'),
 ('customer3', ‘product1')]
Python 중급 네트워크 분석

이분 그래프 투영

cust_nodes = [n for n in G.nodes() if G.nodes[n]
                  ['bipartite'] == 'customers']
cust_nodes
['customer3', 'customer1', 'customer2']
Python 중급 네트워크 분석

이분 그래프 투영

G_cust = nx.bipartite.projected_graph(G, cust_nodes)
list(G_cust.nodes())
['customer1', 'customer3', 'customer2']
list(G_cust.edges())
[('customer1', 'customer2')]
Python 중급 네트워크 분석

차수 중심성

  • 차수 중심성 정의 상기: $$\frac{\text{이웃 수}}{\text{가능한 이웃 수}}$$
  • 분모: 반대 파티션의 노드 수
Python 중급 네트워크 분석

이분 그래프 차수 중심성

nx.bipartite.degree_centrality(G, cust_nodes)
{'customer1': 0.3333333333333333,
 'customer2': 0.3333333333333333,
 'customer3': 0.3333333333333333,
 'product1': 0.3333333333333333,
 'product2': 0.6666666666666666,
 'product3': 0.0}
Python 중급 네트워크 분석

이분 그래프 차수 중심성

nx.degree_centrality(G)
{'customer1': 0.2,
 'customer2': 0.2,
 'customer3': 0.2,
 'product1': 0.2,
 'product2': 0.4,
 'product3': 0.0}
Python 중급 네트워크 분석

연습해 봅시다!

Python 중급 네트워크 분석

Preparing Video For Download...