SlideShare a Scribd company logo
상암동 누리꿈스퀘어
NetworkX를 이용한 네트워크 링크 예측
김경훈
유니스트 수리과학과
kyunghoon@unist.ac.kr
2015년 8월 29일
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 1 / 68
이번 TALK의 목적
1 데이터 조종의 자유로움
2 아이디어 구현의 자유로움
3 융합의 자유로움
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 2 / 68
About me
Speaker
김경훈 (대학원생)
UNIST (Ulsan National Institute of Science and Technology)
자연과학부 수리과학과
Lab
Adviser : Bongsoo Jang
Homepage : http://amath.unist.ac.kr
“Be the light that shines the world with science and technology.”
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 3 / 68
도수 중심성 (Degree Centrality)
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 4 / 68
매개 중심성 (Betweenness Centrality)
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 5 / 68
목차
1 PyCon2014 피드백
K-means Algorithm
얼마나 큰 행렬을 다룰 수 있나요?
네트워크 공부를 위한 기본 서적
2 링크를 예측하기 위한 준비 운동
NumPy
Pandas
3 네트워크 링크 예측
네트워크 링크 예측이란?
네트워크 링크 예측의 매력
4 데모
ipython과 d3.js
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 6 / 68
K-means Algorithm
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 7 / 68
K-means Algorithm
from sklearn import cluster
k = 2
kmeans = cluster.KMeans(n_clusters=k)
kmeans.fit(data)
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 8 / 68
K-means Algorithm
http://cjauvin.blogspot.kr/2014/03/k-means-vs-louvain.html
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 9 / 68
얼마나 큰 행렬을 다룰 수 있나요?
NetworkX는 기본 네트워크 구조로 “dictionary of dictionaries of
dictionaries”를 사용
dict-of-dicts-of-dicts 자료 구조의 장점:
Find edges and remove edges with two dictionary look-ups.
Prefer to “lists” because of fast lookup with sparse storage.
Prefer to “sets” since data can be attached to edge.
G[u][v] returns the edge attribute dictionary.
n in G tests if node n is in graph G.
for n in G: iterates through the graph.
for nbr in G[n]: iterates through neighbors.
https://networkx.github.io/documentation/latest/reference/introduction.html
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 10 / 68
얼마나 큰 행렬을 다룰 수 있나요?
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 11 / 68
얼마나 큰 행렬을 다룰 수 있나요?
Million-scale Graphs Analytic Frameworks
SNAP : http://snap.stanford.edu/snappy/index.html
Billion-scale Graphs Analytic Frameworks
Apache Hama : https://hama.apache.org/ (소개글)
Pegasus : http://www.cs.cmu.edu/~pegasus/
s2graph : https://github.com/daumkakao/s2graph (슬라이드)
Graph Database
Neo4j : http://neo4j.com/
OrientDB : http://orientdb.com/
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 12 / 68
네트워크 공부를 위한 기본 서적
1 Networks: An Introduction by Mark Newman
2 링크 : 21세기를 지배하는 네트워크 과학 LINKED The New Science of Networks
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 13 / 68
링크를 예측하기 위한 준비 운동
1 NumPy : 계산 속도에 최적화된 모듈
2 Pandas : 데이터 구조
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 14 / 68
NumPy: Numerical Python
다차원 배열
1 근접 메모리를 사용하고, C언어로 구성됨
2 하나의 데이터 타입
3 연산이 한 번에 배열 내의 모든 요소에 적용됨
http://www.numpy.org/
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 15 / 68
NumPy: Numerical Python
tic = timeit.default_timer()
for index, value in enumerate(b):
b[index] = value*1.1
toc = timeit.default_timer()
print toc-tic
1.82178592682
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 16 / 68
NumPy: Numerical Python
import numpy as np
import timeit
a = np.arange(1e7)
b = list(a)
tic = timeit.default_timer()
a = a*1.1
toc = timeit.default_timer()
print toc-tic
0.029629945755
사용 방법에 따라, ndarray의 연산 속도는 list()보다 훨씬 빠름.
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 17 / 68
Pandas: Python Data Analysis Library
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 18 / 68
Pandas / get data yahoo
%pylab inline
import pandas as pd
import pandas.io.data
import datetime
start=datetime.datetime(2015,1,1); end=datetime.datetime(2015,8,26)
text = """A, AAPL, AMCC, AMD, AMGN, AMKR, AMNT.OB, AMZN, APC, ASOG.P
text = text.replace(’ ’, ’’).split(’,’)
corps = []
for t in text:
if ’.’ not in t:
corps.append(t)
Code : https://goo.gl/8ddrnS
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 19 / 68
Pandas / get data yahoo
df = pd.io.data.get_data_yahoo(corps, start=start, end=end)
df[’Adj Close’].head()
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 20 / 68
Pandas / Return Value
returns = df[’Adj Close’].pct_change()
corr = returns.corr()
corr
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 21 / 68
Pandas / Correlation
bm = corr>0.5
bm.astype(int)
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 22 / 68
Pandas / Convert to array
mat = bm.astype(int).values
mat
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 23 / 68
NetworkX / from numpy matrix
import networkx as nx
graph = nx.from_numpy_matrix(mat)
graph = nx.relabel_nodes(graph, dict(enumerate(bm.columns)))
nx.draw(graph, with_labels=True)
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 24 / 68
NetworkX / figsize
plt.figure(figsize=(20, 20))
nx.draw_spring(graph, with_labels=True)
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 25 / 68
NetworkX / figsize
first = sorted(nx.connected_components(graph),
key=len, reverse=True)[0]
G = graph.subgraph(first)
nx.draw(G, with_labels=True)
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 26 / 68
NetworkX / 결국 Gephi에서 작업?
nx.write_gexf(G, ’graph.gexf’)
Gephi에서 gexf 열기
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 27 / 68
KoNLPy
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 28 / 68
mecab-ko
은전한닢 프로젝트( http://eunjeon.blogspot.kr/ )
검색에서 쓸만한 오픈소스 한국어 형태소 분석기를 만들자! by 이용운, 유영호
$ sudo docker pull koorukuroo/mecab-ko
$ sudo docker run -i -t koorukuroo/mecab-ko:0.1
안녕하세요
안녕 NNG,*,T,안녕,*,*,*,*
하 XSV,*,F,하,*,*,*,*
세요 EP+EF,*,F,세요,Inflect,EP,EF,시/EP/*+어요/EF/*
EOS
https://github.com/koorukuroo/mecab-ko
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 29 / 68
mecab-ko
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 30 / 68
mecab-ko-web
$ sudo docker pull koorukuroo/mecab-ko-web
$ sudo docker run -i -t koorukuroo/mecab-ko-web:0.1
172.17.0.43 (Docker Container IP)
127.0.0.1
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
>>> import urllib2
>>> response = urllib2.urlopen(’http://172.17.0.43:5000/?text=안녕’)
>>> text = response.read()
>>> print text
안녕 NNG,*,T,안녕,*,*,*,*
EOS
https://github.com/koorukuroo/mecab-ko-web
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 31 / 68
mecab api
http://information.center/api/korean?sc=APIKEY&s=안녕하세요
http://information.center/korean
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 32 / 68
mecab api
import Umorpheme.morpheme as um
from collections import OrderedDict
s = ’유니스트는 울산에 있습니다’
server = ’http://information.center/api/korean’
apikey = ’’ # Register at http://information.center/korean
data = um.analyzer(s, server, apikey, ’유니스트,UNIST’, 1)
temp =
for key, value in data.items():
temp[int(key)] = value
data = OrderedDict(sorted(temp.items()))
for i, j in data.iteritems():
print i, j[’data’], j[’feature’]
0 유니스트 CUSTOM
1 는 JX
2 울산 NNP
3 에 JKB
4 있 VV
5 습니다 EC
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 33 / 68
Pandas에 대한 자세한 내용은..
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 34 / 68
링크 예측이란?
사회망(social networks)에서 링크 예측이란
지금의 네트워크에서 빠진 링크를 예측하는 것
미래의 네트워크에서 새롭게 나타나거나 사라질 링크를 예측하는 것
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 35 / 68
링크 예측이란?
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 36 / 68
링크 예측이란?
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 37 / 68
링크 예측 연구 상황
키워드 “link prediction social network”
Wang, Peng, et al. ”Link prediction in social networks: the state-of-the-art.” Science China Information Sciences 58.1 (2015):
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 38 / 68
네트워크 링크 예측의 매력
1 추천 시스템
친구 추천 (12’)
공동저자 추천 (07’)
온라인 쇼핑몰의 상품 추천 (11’)
특허 추천 (13’)
타분야 협력자 추천 (12’)
연락처 추천 (11’)
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 39 / 68
네트워크 링크 예측의 매력
2 복잡계 연구
네트워크 진화 연구 (02’)
웹사이트 링크 예측 (02’)
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 40 / 68
네트워크 링크 예측의 매력
3 다양한 분야에 적용
헬스케어 (12’)
단백질 네트워크 (12’)
비정상적 커뮤니케이션 확인 (09’)
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 41 / 68
네트워크 링크 예측
사회망
G(V , E) at t
에 대해,
링크가 생기거나 사라지는 것을 (t′ > t)
빠진 링크나 관찰되지 않은 링크가 있는 것을 (at t)
찾아내는 것.
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 42 / 68
링크 예측 프레임워크
Wang, Peng, et al. ”Link prediction in social networks: the state-of-the-art.”
Science China Information Sciences 58.1 (2015): 1-38.
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 43 / 68
링크 예측의 이론
https://www.cs.umd.edu/class/spring2008/cmsc828g/
Slides/link-prediction.pdf
Liben‐Nowell, David, and Jon Kleinberg. “The link‐prediction problem
for social networks.” Journal of the American society for information
science and technology 58.7 (2007): 1019-1031.
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 44 / 68
링크 예측의 세분화
Wang, Peng, et al. ”Link prediction in social networks: the state-of-the-art.”
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 45 / 68
링크 예측의 세분화
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 46 / 68
링크 예측의 기본 정의
Γ(x) : 점 x의 이웃들의 집합
|Γ(x)| : 점 x의 이웃들의 개수
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 47 / 68
공통 이웃들
공통 이웃들(Common Neighbors):
CN(u, v) = |Γ(u) ∩ Γ(v)|
본 그래프는 실제가 아닌 가상으로 설정된 상황임을 알려드립니다
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 48 / 68
리소스 할당 지수
리소스 할당 지수(Resource Allocation Index):
w∈Γ(u)∩Γ(v)
1
|Γ(w)|
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 49 / 68
리소스 할당 지수
리소스 할당 지수(Resource Allocation Index):
w∈Γ(u)∩Γ(v)
1
|Γ(w)|
preds = nx.resource_allocation_index(G)
for u, v, p in preds:
print ’(%s, %s) -> %.8f’ % (u, v, p)
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 50 / 68
리소스 할당 지수
(수지, 혜리) -> 0.33333333
(수지, 경훈) -> 0.83333333
(아이유, 민호) -> 1.00000000
(혜리, 민호) -> 0.00000000
(혜리, 경훈) -> 0.33333333
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 51 / 68
리소스 할당 지수
w∈Γ(u)∩Γ(v)
1
|Γ(w)|
(수지, 혜리) -> 0.33333333
(수지, 경훈) -> 0.83333333
(아이유, 민호) -> 1.00000000
(혜리, 민호) -> 0.00000000
(혜리, 경훈) -> 0.33333333
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 52 / 68
한국어 표시하기
pip install --upgrade
git+https://github.com/koorukuroo/networkx_for_unicode
import matplotlib.font_manager as fm
fp1 = fm.FontProperties(fname="./NotoSansKR-Regular.otf")
nx.set_fontproperties(fp1)
G = nx.Graph()
G.add_edge(u’한국어’,u’영어’)
nx.draw(G, with_labels=True)
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 53 / 68
선호적 연결
선호적 연결(Preferential attachment):
|Γ(u)||Γ(v)|
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 54 / 68
선호적 연결
nx.draw_networkx_nodes(G, pos, node_size=500, node_color=’yellow’)
nx.draw_networkx_edges(G, pos, alpha=0.2)
nx.draw_networkx_labels(G, pos, font_size=20);
selected_lines = []
for u in G.nodes_iter():
preds = nx.preferential_attachment(G, [(u, v) for v in nx.non_neighbors(G, u)])
largest = heapq.nlargest(5, preds, key = lambda x: x[2])
for l in largest:
selected_lines.append(l)
subG = nx.Graph()
for line in selected_lines:
print line[0], line[1], line[2]
if line[2]>1:
subG.add_edge(line[0], line[1])
pos_subG = dict()
for s in subG.nodes():
pos_subG[s] = pos[s]
nx.draw_networkx_edges(subG, pos_subG, edge_color=’red’)
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 55 / 68
선호적 연결
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 56 / 68
선호적 연결
degree = nx.degree_centrality(G)
nx.draw_networkx_nodes(G, pos, node_color=’yellow’, nodelist=degree.keys(),
node_size=np.array(degree.values())*10000)
nx.draw_networkx_edges(G, pos, alpha=0.2)
nx.draw_networkx_labels(G, pos, font_size=20);
selected_lines = []
for u in G.nodes_iter():
preds = nx.preferential_attachment(G, [(u, v) for v in nx.non_neighbors(G, u)])
largest = heapq.nlargest(5, preds, key = lambda x: x[2])
for l in largest:
selected_lines.append(l)
subG = nx.Graph()
for line in selected_lines:
print line[0], line[1], line[2]
if line[2]>1:
subG.add_edge(line[0], line[1])
pos_subG = dict()
for s in subG.nodes():
pos_subG[s] = pos[s]
nx.draw_networkx_edges(subG, pos_subG, edge_color=’red’)
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 57 / 68
선호적 연결
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 58 / 68
NetworkX의 Link Prediction 함수들
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 59 / 68
LPmade
https://github.com/rlichtenwalter/LPmade
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 60 / 68
데모
matplotlib
ipython과 d3.js
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 61 / 68
ipython과 d3.js
from IPython.display import display, HTML
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 62 / 68
d3.js (Data-Driven Documents)
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 63 / 68
ipython에서 파일 쓰기
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 64 / 68
ipython에서 d3.js 가동하기
코드 https://goo.gl/LpxsKc
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 65 / 68
ipython과 d3.js
edges = d3_graph(G)
make_html_graph(edges, 1000, 500) # make_html_graph(edges)
%%HTML
<iframe src="d3.html" width=100% height=500 frameborder=0></iframe>
Demo 화면 : http://i.imgur.com/FeQ9kii.gif
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 66 / 68
다시 한 번, 이번 TALK의 목적
1 데이터 조종의 자유로움
2 아이디어 구현의 자유로움
3 융합의 자유로움
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 67 / 68
The End
김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 68 / 68

More Related Content

Viewers also liked

Ppt
PptPpt
Link prediction 방법의 개념 및 활용
Link prediction 방법의 개념 및 활용Link prediction 방법의 개념 및 활용
Link prediction 방법의 개념 및 활용
Kyunghoon Kim
 
사회 연결망의 링크 예측
사회 연결망의 링크 예측사회 연결망의 링크 예측
사회 연결망의 링크 예측
Kyunghoon Kim
 
Who to follow and why: link prediction with explanations
Who to follow and why: link prediction with explanationsWho to follow and why: link prediction with explanations
Who to follow and why: link prediction with explanations
Nicola Barbieri
 
SNA & R (20121011)
SNA & R (20121011)SNA & R (20121011)
SNA & R (20121011)주영 송
 
오픈데이터와 오픈소스 소프트웨어를 이용한 의료이용정보의 시각화
오픈데이터와 오픈소스 소프트웨어를 이용한 의료이용정보의 시각화오픈데이터와 오픈소스 소프트웨어를 이용한 의료이용정보의 시각화
오픈데이터와 오픈소스 소프트웨어를 이용한 의료이용정보의 시각화
r-kor
 
한글 언어 자원과 R: KoNLP 개선과 활용
한글 언어 자원과 R: KoNLP 개선과 활용한글 언어 자원과 R: KoNLP 개선과 활용
한글 언어 자원과 R: KoNLP 개선과 활용
r-kor
 

Viewers also liked (8)

Social Networks
Social NetworksSocial Networks
Social Networks
 
Ppt
PptPpt
Ppt
 
Link prediction 방법의 개념 및 활용
Link prediction 방법의 개념 및 활용Link prediction 방법의 개념 및 활용
Link prediction 방법의 개념 및 활용
 
사회 연결망의 링크 예측
사회 연결망의 링크 예측사회 연결망의 링크 예측
사회 연결망의 링크 예측
 
Who to follow and why: link prediction with explanations
Who to follow and why: link prediction with explanationsWho to follow and why: link prediction with explanations
Who to follow and why: link prediction with explanations
 
SNA & R (20121011)
SNA & R (20121011)SNA & R (20121011)
SNA & R (20121011)
 
오픈데이터와 오픈소스 소프트웨어를 이용한 의료이용정보의 시각화
오픈데이터와 오픈소스 소프트웨어를 이용한 의료이용정보의 시각화오픈데이터와 오픈소스 소프트웨어를 이용한 의료이용정보의 시각화
오픈데이터와 오픈소스 소프트웨어를 이용한 의료이용정보의 시각화
 
한글 언어 자원과 R: KoNLP 개선과 활용
한글 언어 자원과 R: KoNLP 개선과 활용한글 언어 자원과 R: KoNLP 개선과 활용
한글 언어 자원과 R: KoNLP 개선과 활용
 

Similar to [20150829, PyCon2015] NetworkX를 이용한 네트워크 링크 예측

KrKwic내용분석특강(november2006)
KrKwic내용분석특강(november2006)KrKwic내용분석특강(november2006)
KrKwic내용분석특강(november2006)
Han Woo PARK
 
시카고 Array of Things 프로젝트 리뷰
시카고 Array of Things 프로젝트 리뷰시카고 Array of Things 프로젝트 리뷰
시카고 Array of Things 프로젝트 리뷰
Kyuho Kim
 
[Graduation Project] 전자석을 이용한 타자 연습기
[Graduation Project] 전자석을 이용한 타자 연습기[Graduation Project] 전자석을 이용한 타자 연습기
[Graduation Project] 전자석을 이용한 타자 연습기
Junyoung Jung
 
01 [Coreonto] 툴킷 개발안
01 [Coreonto] 툴킷 개발안01 [Coreonto] 툴킷 개발안
01 [Coreonto] 툴킷 개발안sejin nam
 
KCSE 2015 Tutorial 빅데이터 분석 기술의 소프트웨어 공학 분야 활용 (...
KCSE 2015 Tutorial 빅데이터 분석 기술의  소프트웨어 공학 분야 활용 (...KCSE 2015 Tutorial 빅데이터 분석 기술의  소프트웨어 공학 분야 활용 (...
KCSE 2015 Tutorial 빅데이터 분석 기술의 소프트웨어 공학 분야 활용 (...
Chanjin Park
 
망중립성 강좌 : 4강 (강장묵)
망중립성 강좌 : 4강 (강장묵) 망중립성 강좌 : 4강 (강장묵)
망중립성 강좌 : 4강 (강장묵)
nnforum
 
A Financial Company Story of Bringing Open Source and ML in
A Financial Company Story of Bringing Open Source and ML inA Financial Company Story of Bringing Open Source and ML in
A Financial Company Story of Bringing Open Source and ML in
Dataya Nolja
 
NS-3(Network Simulator 3) 소개
NS-3(Network Simulator 3) 소개NS-3(Network Simulator 3) 소개
NS-3(Network Simulator 3) 소개
공학코드
 
Genomics and BigData - case study
Genomics and BigData - case studyGenomics and BigData - case study
Genomics and BigData - case study
Hong ChangBum
 
Lecture 1: Introduction to Python and TensorFlow
Lecture 1: Introduction to Python and TensorFlowLecture 1: Introduction to Python and TensorFlow
Lecture 1: Introduction to Python and TensorFlow
Sang Jun Lee
 
[오픈소스컨설팅]오픈스택에 대하여
[오픈소스컨설팅]오픈스택에 대하여[오픈소스컨설팅]오픈스택에 대하여
[오픈소스컨설팅]오픈스택에 대하여
Ji-Woong Choi
 
20141214 빅데이터실전기술 - 유사도 및 군집화 방법 (Similarity&Clustering)
20141214 빅데이터실전기술 - 유사도 및 군집화 방법 (Similarity&Clustering) 20141214 빅데이터실전기술 - 유사도 및 군집화 방법 (Similarity&Clustering)
20141214 빅데이터실전기술 - 유사도 및 군집화 방법 (Similarity&Clustering)
Tae Young Lee
 
Python(basic)
Python(basic)Python(basic)
Python(basic)
POSTECH
 
데이터분석의 길 5: “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)
데이터분석의 길 5:  “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)데이터분석의 길 5:  “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)
데이터분석의 길 5: “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)
Jaimie Kwon (권재명)
 
[232] 수퍼컴퓨팅과 데이터 어낼리틱스
[232] 수퍼컴퓨팅과 데이터 어낼리틱스[232] 수퍼컴퓨팅과 데이터 어낼리틱스
[232] 수퍼컴퓨팅과 데이터 어낼리틱스
NAVER D2
 
순환신경망(Recurrent neural networks) 개요
순환신경망(Recurrent neural networks) 개요순환신경망(Recurrent neural networks) 개요
순환신경망(Recurrent neural networks) 개요
Byoung-Hee Kim
 
Nnstreamer stream pipeline for arbitrary neural networks
Nnstreamer stream pipeline for arbitrary neural networksNnstreamer stream pipeline for arbitrary neural networks
Nnstreamer stream pipeline for arbitrary neural networks
NAVER Engineering
 
Elastic Stack & Data pipeline
Elastic Stack & Data pipelineElastic Stack & Data pipeline
Elastic Stack & Data pipeline
Jongho Woo
 
부록2 node xl 메뉴얼(11aug2011)
부록2 node xl 메뉴얼(11aug2011)부록2 node xl 메뉴얼(11aug2011)
부록2 node xl 메뉴얼(11aug2011)Han Woo PARK
 
How to do things with 'BigKinds'
How to do things with 'BigKinds'How to do things with 'BigKinds'
How to do things with 'BigKinds'
Daemin Park
 

Similar to [20150829, PyCon2015] NetworkX를 이용한 네트워크 링크 예측 (20)

KrKwic내용분석특강(november2006)
KrKwic내용분석특강(november2006)KrKwic내용분석특강(november2006)
KrKwic내용분석특강(november2006)
 
시카고 Array of Things 프로젝트 리뷰
시카고 Array of Things 프로젝트 리뷰시카고 Array of Things 프로젝트 리뷰
시카고 Array of Things 프로젝트 리뷰
 
[Graduation Project] 전자석을 이용한 타자 연습기
[Graduation Project] 전자석을 이용한 타자 연습기[Graduation Project] 전자석을 이용한 타자 연습기
[Graduation Project] 전자석을 이용한 타자 연습기
 
01 [Coreonto] 툴킷 개발안
01 [Coreonto] 툴킷 개발안01 [Coreonto] 툴킷 개발안
01 [Coreonto] 툴킷 개발안
 
KCSE 2015 Tutorial 빅데이터 분석 기술의 소프트웨어 공학 분야 활용 (...
KCSE 2015 Tutorial 빅데이터 분석 기술의  소프트웨어 공학 분야 활용 (...KCSE 2015 Tutorial 빅데이터 분석 기술의  소프트웨어 공학 분야 활용 (...
KCSE 2015 Tutorial 빅데이터 분석 기술의 소프트웨어 공학 분야 활용 (...
 
망중립성 강좌 : 4강 (강장묵)
망중립성 강좌 : 4강 (강장묵) 망중립성 강좌 : 4강 (강장묵)
망중립성 강좌 : 4강 (강장묵)
 
A Financial Company Story of Bringing Open Source and ML in
A Financial Company Story of Bringing Open Source and ML inA Financial Company Story of Bringing Open Source and ML in
A Financial Company Story of Bringing Open Source and ML in
 
NS-3(Network Simulator 3) 소개
NS-3(Network Simulator 3) 소개NS-3(Network Simulator 3) 소개
NS-3(Network Simulator 3) 소개
 
Genomics and BigData - case study
Genomics and BigData - case studyGenomics and BigData - case study
Genomics and BigData - case study
 
Lecture 1: Introduction to Python and TensorFlow
Lecture 1: Introduction to Python and TensorFlowLecture 1: Introduction to Python and TensorFlow
Lecture 1: Introduction to Python and TensorFlow
 
[오픈소스컨설팅]오픈스택에 대하여
[오픈소스컨설팅]오픈스택에 대하여[오픈소스컨설팅]오픈스택에 대하여
[오픈소스컨설팅]오픈스택에 대하여
 
20141214 빅데이터실전기술 - 유사도 및 군집화 방법 (Similarity&Clustering)
20141214 빅데이터실전기술 - 유사도 및 군집화 방법 (Similarity&Clustering) 20141214 빅데이터실전기술 - 유사도 및 군집화 방법 (Similarity&Clustering)
20141214 빅데이터실전기술 - 유사도 및 군집화 방법 (Similarity&Clustering)
 
Python(basic)
Python(basic)Python(basic)
Python(basic)
 
데이터분석의 길 5: “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)
데이터분석의 길 5:  “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)데이터분석의 길 5:  “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)
데이터분석의 길 5: “고수는 큰자료를 두려워하지 않는다” (클릭확률예측 상편)
 
[232] 수퍼컴퓨팅과 데이터 어낼리틱스
[232] 수퍼컴퓨팅과 데이터 어낼리틱스[232] 수퍼컴퓨팅과 데이터 어낼리틱스
[232] 수퍼컴퓨팅과 데이터 어낼리틱스
 
순환신경망(Recurrent neural networks) 개요
순환신경망(Recurrent neural networks) 개요순환신경망(Recurrent neural networks) 개요
순환신경망(Recurrent neural networks) 개요
 
Nnstreamer stream pipeline for arbitrary neural networks
Nnstreamer stream pipeline for arbitrary neural networksNnstreamer stream pipeline for arbitrary neural networks
Nnstreamer stream pipeline for arbitrary neural networks
 
Elastic Stack & Data pipeline
Elastic Stack & Data pipelineElastic Stack & Data pipeline
Elastic Stack & Data pipeline
 
부록2 node xl 메뉴얼(11aug2011)
부록2 node xl 메뉴얼(11aug2011)부록2 node xl 메뉴얼(11aug2011)
부록2 node xl 메뉴얼(11aug2011)
 
How to do things with 'BigKinds'
How to do things with 'BigKinds'How to do things with 'BigKinds'
How to do things with 'BigKinds'
 

More from Kyunghoon Kim

넥스트 노멀 - 인간과 AI의 협업
넥스트 노멀 - 인간과 AI의 협업넥스트 노멀 - 인간과 AI의 협업
넥스트 노멀 - 인간과 AI의 협업
Kyunghoon Kim
 
토론하는 AI 김컴재와 AI 조향사 센트리아
토론하는 AI 김컴재와 AI 조향사 센트리아토론하는 AI 김컴재와 AI 조향사 센트리아
토론하는 AI 김컴재와 AI 조향사 센트리아
Kyunghoon Kim
 
빅데이터의 다음 단계는 예측 분석이다
빅데이터의 다음 단계는 예측 분석이다빅데이터의 다음 단계는 예측 분석이다
빅데이터의 다음 단계는 예측 분석이다
Kyunghoon Kim
 
중학생을 위한 4차 산업혁명 시대의 인공지능 이야기
중학생을 위한 4차 산업혁명 시대의 인공지능 이야기중학생을 위한 4차 산업혁명 시대의 인공지능 이야기
중학생을 위한 4차 산업혁명 시대의 인공지능 이야기
Kyunghoon Kim
 
업무 자동화
업무 자동화업무 자동화
업무 자동화
Kyunghoon Kim
 
4차 산업혁명 시대의 진로와 진학
4차 산업혁명 시대의 진로와 진학4차 산업혁명 시대의 진로와 진학
4차 산업혁명 시대의 진로와 진학
Kyunghoon Kim
 
20200620 신호와 소음 독서토론
20200620 신호와 소음 독서토론20200620 신호와 소음 독서토론
20200620 신호와 소음 독서토론
Kyunghoon Kim
 
중학생을 위한 인공지능 이야기
중학생을 위한 인공지능 이야기중학생을 위한 인공지능 이야기
중학생을 위한 인공지능 이야기
Kyunghoon Kim
 
슬쩍 해보는 선형대수학
슬쩍 해보는 선형대수학슬쩍 해보는 선형대수학
슬쩍 해보는 선형대수학
Kyunghoon Kim
 
파이썬으로 해보는 이미지 처리
파이썬으로 해보는 이미지 처리파이썬으로 해보는 이미지 처리
파이썬으로 해보는 이미지 처리
Kyunghoon Kim
 
기계가 선형대수학을 통해 한국어를 이해하는 방법
기계가 선형대수학을 통해 한국어를 이해하는 방법기계가 선형대수학을 통해 한국어를 이해하는 방법
기계가 선형대수학을 통해 한국어를 이해하는 방법
Kyunghoon Kim
 
공공데이터 활용사례
공공데이터 활용사례공공데이터 활용사례
공공데이터 활용사례
Kyunghoon Kim
 
기계학습, 딥러닝, 인공지능 사이의 차이점 이해하기
기계학습, 딥러닝, 인공지능 사이의 차이점 이해하기기계학습, 딥러닝, 인공지능 사이의 차이점 이해하기
기계학습, 딥러닝, 인공지능 사이의 차이점 이해하기
Kyunghoon Kim
 
Korean Text mining
Korean Text miningKorean Text mining
Korean Text mining
Kyunghoon Kim
 
2018 인공지능에 대하여
2018 인공지능에 대하여2018 인공지능에 대하여
2018 인공지능에 대하여
Kyunghoon Kim
 
Naive bayes Classification using Python3
Naive bayes Classification using Python3Naive bayes Classification using Python3
Naive bayes Classification using Python3
Kyunghoon Kim
 
Basic statistics using Python3
Basic statistics using Python3Basic statistics using Python3
Basic statistics using Python3
Kyunghoon Kim
 
[20160813, PyCon2016APAC] 뉴스를 재미있게 만드는 방법; 뉴스잼
[20160813, PyCon2016APAC] 뉴스를 재미있게 만드는 방법; 뉴스잼[20160813, PyCon2016APAC] 뉴스를 재미있게 만드는 방법; 뉴스잼
[20160813, PyCon2016APAC] 뉴스를 재미있게 만드는 방법; 뉴스잼
Kyunghoon Kim
 
Topic Modeling
Topic ModelingTopic Modeling
Topic Modeling
Kyunghoon Kim
 
NMF with python
NMF with pythonNMF with python
NMF with python
Kyunghoon Kim
 

More from Kyunghoon Kim (20)

넥스트 노멀 - 인간과 AI의 협업
넥스트 노멀 - 인간과 AI의 협업넥스트 노멀 - 인간과 AI의 협업
넥스트 노멀 - 인간과 AI의 협업
 
토론하는 AI 김컴재와 AI 조향사 센트리아
토론하는 AI 김컴재와 AI 조향사 센트리아토론하는 AI 김컴재와 AI 조향사 센트리아
토론하는 AI 김컴재와 AI 조향사 센트리아
 
빅데이터의 다음 단계는 예측 분석이다
빅데이터의 다음 단계는 예측 분석이다빅데이터의 다음 단계는 예측 분석이다
빅데이터의 다음 단계는 예측 분석이다
 
중학생을 위한 4차 산업혁명 시대의 인공지능 이야기
중학생을 위한 4차 산업혁명 시대의 인공지능 이야기중학생을 위한 4차 산업혁명 시대의 인공지능 이야기
중학생을 위한 4차 산업혁명 시대의 인공지능 이야기
 
업무 자동화
업무 자동화업무 자동화
업무 자동화
 
4차 산업혁명 시대의 진로와 진학
4차 산업혁명 시대의 진로와 진학4차 산업혁명 시대의 진로와 진학
4차 산업혁명 시대의 진로와 진학
 
20200620 신호와 소음 독서토론
20200620 신호와 소음 독서토론20200620 신호와 소음 독서토론
20200620 신호와 소음 독서토론
 
중학생을 위한 인공지능 이야기
중학생을 위한 인공지능 이야기중학생을 위한 인공지능 이야기
중학생을 위한 인공지능 이야기
 
슬쩍 해보는 선형대수학
슬쩍 해보는 선형대수학슬쩍 해보는 선형대수학
슬쩍 해보는 선형대수학
 
파이썬으로 해보는 이미지 처리
파이썬으로 해보는 이미지 처리파이썬으로 해보는 이미지 처리
파이썬으로 해보는 이미지 처리
 
기계가 선형대수학을 통해 한국어를 이해하는 방법
기계가 선형대수학을 통해 한국어를 이해하는 방법기계가 선형대수학을 통해 한국어를 이해하는 방법
기계가 선형대수학을 통해 한국어를 이해하는 방법
 
공공데이터 활용사례
공공데이터 활용사례공공데이터 활용사례
공공데이터 활용사례
 
기계학습, 딥러닝, 인공지능 사이의 차이점 이해하기
기계학습, 딥러닝, 인공지능 사이의 차이점 이해하기기계학습, 딥러닝, 인공지능 사이의 차이점 이해하기
기계학습, 딥러닝, 인공지능 사이의 차이점 이해하기
 
Korean Text mining
Korean Text miningKorean Text mining
Korean Text mining
 
2018 인공지능에 대하여
2018 인공지능에 대하여2018 인공지능에 대하여
2018 인공지능에 대하여
 
Naive bayes Classification using Python3
Naive bayes Classification using Python3Naive bayes Classification using Python3
Naive bayes Classification using Python3
 
Basic statistics using Python3
Basic statistics using Python3Basic statistics using Python3
Basic statistics using Python3
 
[20160813, PyCon2016APAC] 뉴스를 재미있게 만드는 방법; 뉴스잼
[20160813, PyCon2016APAC] 뉴스를 재미있게 만드는 방법; 뉴스잼[20160813, PyCon2016APAC] 뉴스를 재미있게 만드는 방법; 뉴스잼
[20160813, PyCon2016APAC] 뉴스를 재미있게 만드는 방법; 뉴스잼
 
Topic Modeling
Topic ModelingTopic Modeling
Topic Modeling
 
NMF with python
NMF with pythonNMF with python
NMF with python
 

[20150829, PyCon2015] NetworkX를 이용한 네트워크 링크 예측

  • 1. 상암동 누리꿈스퀘어 NetworkX를 이용한 네트워크 링크 예측 김경훈 유니스트 수리과학과 kyunghoon@unist.ac.kr 2015년 8월 29일 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 1 / 68
  • 2. 이번 TALK의 목적 1 데이터 조종의 자유로움 2 아이디어 구현의 자유로움 3 융합의 자유로움 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 2 / 68
  • 3. About me Speaker 김경훈 (대학원생) UNIST (Ulsan National Institute of Science and Technology) 자연과학부 수리과학과 Lab Adviser : Bongsoo Jang Homepage : http://amath.unist.ac.kr “Be the light that shines the world with science and technology.” 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 3 / 68
  • 4. 도수 중심성 (Degree Centrality) 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 4 / 68
  • 5. 매개 중심성 (Betweenness Centrality) 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 5 / 68
  • 6. 목차 1 PyCon2014 피드백 K-means Algorithm 얼마나 큰 행렬을 다룰 수 있나요? 네트워크 공부를 위한 기본 서적 2 링크를 예측하기 위한 준비 운동 NumPy Pandas 3 네트워크 링크 예측 네트워크 링크 예측이란? 네트워크 링크 예측의 매력 4 데모 ipython과 d3.js 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 6 / 68
  • 7. K-means Algorithm 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 7 / 68
  • 8. K-means Algorithm from sklearn import cluster k = 2 kmeans = cluster.KMeans(n_clusters=k) kmeans.fit(data) 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 8 / 68
  • 10. 얼마나 큰 행렬을 다룰 수 있나요? NetworkX는 기본 네트워크 구조로 “dictionary of dictionaries of dictionaries”를 사용 dict-of-dicts-of-dicts 자료 구조의 장점: Find edges and remove edges with two dictionary look-ups. Prefer to “lists” because of fast lookup with sparse storage. Prefer to “sets” since data can be attached to edge. G[u][v] returns the edge attribute dictionary. n in G tests if node n is in graph G. for n in G: iterates through the graph. for nbr in G[n]: iterates through neighbors. https://networkx.github.io/documentation/latest/reference/introduction.html 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 10 / 68
  • 11. 얼마나 큰 행렬을 다룰 수 있나요? 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 11 / 68
  • 12. 얼마나 큰 행렬을 다룰 수 있나요? Million-scale Graphs Analytic Frameworks SNAP : http://snap.stanford.edu/snappy/index.html Billion-scale Graphs Analytic Frameworks Apache Hama : https://hama.apache.org/ (소개글) Pegasus : http://www.cs.cmu.edu/~pegasus/ s2graph : https://github.com/daumkakao/s2graph (슬라이드) Graph Database Neo4j : http://neo4j.com/ OrientDB : http://orientdb.com/ 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 12 / 68
  • 13. 네트워크 공부를 위한 기본 서적 1 Networks: An Introduction by Mark Newman 2 링크 : 21세기를 지배하는 네트워크 과학 LINKED The New Science of Networks 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 13 / 68
  • 14. 링크를 예측하기 위한 준비 운동 1 NumPy : 계산 속도에 최적화된 모듈 2 Pandas : 데이터 구조 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 14 / 68
  • 15. NumPy: Numerical Python 다차원 배열 1 근접 메모리를 사용하고, C언어로 구성됨 2 하나의 데이터 타입 3 연산이 한 번에 배열 내의 모든 요소에 적용됨 http://www.numpy.org/ 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 15 / 68
  • 16. NumPy: Numerical Python tic = timeit.default_timer() for index, value in enumerate(b): b[index] = value*1.1 toc = timeit.default_timer() print toc-tic 1.82178592682 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 16 / 68
  • 17. NumPy: Numerical Python import numpy as np import timeit a = np.arange(1e7) b = list(a) tic = timeit.default_timer() a = a*1.1 toc = timeit.default_timer() print toc-tic 0.029629945755 사용 방법에 따라, ndarray의 연산 속도는 list()보다 훨씬 빠름. 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 17 / 68
  • 18. Pandas: Python Data Analysis Library 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 18 / 68
  • 19. Pandas / get data yahoo %pylab inline import pandas as pd import pandas.io.data import datetime start=datetime.datetime(2015,1,1); end=datetime.datetime(2015,8,26) text = """A, AAPL, AMCC, AMD, AMGN, AMKR, AMNT.OB, AMZN, APC, ASOG.P text = text.replace(’ ’, ’’).split(’,’) corps = [] for t in text: if ’.’ not in t: corps.append(t) Code : https://goo.gl/8ddrnS 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 19 / 68
  • 20. Pandas / get data yahoo df = pd.io.data.get_data_yahoo(corps, start=start, end=end) df[’Adj Close’].head() 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 20 / 68
  • 21. Pandas / Return Value returns = df[’Adj Close’].pct_change() corr = returns.corr() corr 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 21 / 68
  • 22. Pandas / Correlation bm = corr>0.5 bm.astype(int) 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 22 / 68
  • 23. Pandas / Convert to array mat = bm.astype(int).values mat 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 23 / 68
  • 24. NetworkX / from numpy matrix import networkx as nx graph = nx.from_numpy_matrix(mat) graph = nx.relabel_nodes(graph, dict(enumerate(bm.columns))) nx.draw(graph, with_labels=True) 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 24 / 68
  • 25. NetworkX / figsize plt.figure(figsize=(20, 20)) nx.draw_spring(graph, with_labels=True) 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 25 / 68
  • 26. NetworkX / figsize first = sorted(nx.connected_components(graph), key=len, reverse=True)[0] G = graph.subgraph(first) nx.draw(G, with_labels=True) 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 26 / 68
  • 27. NetworkX / 결국 Gephi에서 작업? nx.write_gexf(G, ’graph.gexf’) Gephi에서 gexf 열기 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 27 / 68
  • 28. KoNLPy 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 28 / 68
  • 29. mecab-ko 은전한닢 프로젝트( http://eunjeon.blogspot.kr/ ) 검색에서 쓸만한 오픈소스 한국어 형태소 분석기를 만들자! by 이용운, 유영호 $ sudo docker pull koorukuroo/mecab-ko $ sudo docker run -i -t koorukuroo/mecab-ko:0.1 안녕하세요 안녕 NNG,*,T,안녕,*,*,*,* 하 XSV,*,F,하,*,*,*,* 세요 EP+EF,*,F,세요,Inflect,EP,EF,시/EP/*+어요/EF/* EOS https://github.com/koorukuroo/mecab-ko 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 29 / 68
  • 30. mecab-ko 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 30 / 68
  • 31. mecab-ko-web $ sudo docker pull koorukuroo/mecab-ko-web $ sudo docker run -i -t koorukuroo/mecab-ko-web:0.1 172.17.0.43 (Docker Container IP) 127.0.0.1 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) >>> import urllib2 >>> response = urllib2.urlopen(’http://172.17.0.43:5000/?text=안녕’) >>> text = response.read() >>> print text 안녕 NNG,*,T,안녕,*,*,*,* EOS https://github.com/koorukuroo/mecab-ko-web 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 31 / 68
  • 33. mecab api import Umorpheme.morpheme as um from collections import OrderedDict s = ’유니스트는 울산에 있습니다’ server = ’http://information.center/api/korean’ apikey = ’’ # Register at http://information.center/korean data = um.analyzer(s, server, apikey, ’유니스트,UNIST’, 1) temp = for key, value in data.items(): temp[int(key)] = value data = OrderedDict(sorted(temp.items())) for i, j in data.iteritems(): print i, j[’data’], j[’feature’] 0 유니스트 CUSTOM 1 는 JX 2 울산 NNP 3 에 JKB 4 있 VV 5 습니다 EC 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 33 / 68
  • 34. Pandas에 대한 자세한 내용은.. 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 34 / 68
  • 35. 링크 예측이란? 사회망(social networks)에서 링크 예측이란 지금의 네트워크에서 빠진 링크를 예측하는 것 미래의 네트워크에서 새롭게 나타나거나 사라질 링크를 예측하는 것 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 35 / 68
  • 36. 링크 예측이란? 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 36 / 68
  • 37. 링크 예측이란? 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 37 / 68
  • 38. 링크 예측 연구 상황 키워드 “link prediction social network” Wang, Peng, et al. ”Link prediction in social networks: the state-of-the-art.” Science China Information Sciences 58.1 (2015): 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 38 / 68
  • 39. 네트워크 링크 예측의 매력 1 추천 시스템 친구 추천 (12’) 공동저자 추천 (07’) 온라인 쇼핑몰의 상품 추천 (11’) 특허 추천 (13’) 타분야 협력자 추천 (12’) 연락처 추천 (11’) 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 39 / 68
  • 40. 네트워크 링크 예측의 매력 2 복잡계 연구 네트워크 진화 연구 (02’) 웹사이트 링크 예측 (02’) 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 40 / 68
  • 41. 네트워크 링크 예측의 매력 3 다양한 분야에 적용 헬스케어 (12’) 단백질 네트워크 (12’) 비정상적 커뮤니케이션 확인 (09’) 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 41 / 68
  • 42. 네트워크 링크 예측 사회망 G(V , E) at t 에 대해, 링크가 생기거나 사라지는 것을 (t′ > t) 빠진 링크나 관찰되지 않은 링크가 있는 것을 (at t) 찾아내는 것. 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 42 / 68
  • 43. 링크 예측 프레임워크 Wang, Peng, et al. ”Link prediction in social networks: the state-of-the-art.” Science China Information Sciences 58.1 (2015): 1-38. 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 43 / 68
  • 44. 링크 예측의 이론 https://www.cs.umd.edu/class/spring2008/cmsc828g/ Slides/link-prediction.pdf Liben‐Nowell, David, and Jon Kleinberg. “The link‐prediction problem for social networks.” Journal of the American society for information science and technology 58.7 (2007): 1019-1031. 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 44 / 68
  • 45. 링크 예측의 세분화 Wang, Peng, et al. ”Link prediction in social networks: the state-of-the-art.” 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 45 / 68
  • 46. 링크 예측의 세분화 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 46 / 68
  • 47. 링크 예측의 기본 정의 Γ(x) : 점 x의 이웃들의 집합 |Γ(x)| : 점 x의 이웃들의 개수 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 47 / 68
  • 48. 공통 이웃들 공통 이웃들(Common Neighbors): CN(u, v) = |Γ(u) ∩ Γ(v)| 본 그래프는 실제가 아닌 가상으로 설정된 상황임을 알려드립니다 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 48 / 68
  • 49. 리소스 할당 지수 리소스 할당 지수(Resource Allocation Index): w∈Γ(u)∩Γ(v) 1 |Γ(w)| 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 49 / 68
  • 50. 리소스 할당 지수 리소스 할당 지수(Resource Allocation Index): w∈Γ(u)∩Γ(v) 1 |Γ(w)| preds = nx.resource_allocation_index(G) for u, v, p in preds: print ’(%s, %s) -> %.8f’ % (u, v, p) 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 50 / 68
  • 51. 리소스 할당 지수 (수지, 혜리) -> 0.33333333 (수지, 경훈) -> 0.83333333 (아이유, 민호) -> 1.00000000 (혜리, 민호) -> 0.00000000 (혜리, 경훈) -> 0.33333333 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 51 / 68
  • 52. 리소스 할당 지수 w∈Γ(u)∩Γ(v) 1 |Γ(w)| (수지, 혜리) -> 0.33333333 (수지, 경훈) -> 0.83333333 (아이유, 민호) -> 1.00000000 (혜리, 민호) -> 0.00000000 (혜리, 경훈) -> 0.33333333 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 52 / 68
  • 53. 한국어 표시하기 pip install --upgrade git+https://github.com/koorukuroo/networkx_for_unicode import matplotlib.font_manager as fm fp1 = fm.FontProperties(fname="./NotoSansKR-Regular.otf") nx.set_fontproperties(fp1) G = nx.Graph() G.add_edge(u’한국어’,u’영어’) nx.draw(G, with_labels=True) 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 53 / 68
  • 54. 선호적 연결 선호적 연결(Preferential attachment): |Γ(u)||Γ(v)| 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 54 / 68
  • 55. 선호적 연결 nx.draw_networkx_nodes(G, pos, node_size=500, node_color=’yellow’) nx.draw_networkx_edges(G, pos, alpha=0.2) nx.draw_networkx_labels(G, pos, font_size=20); selected_lines = [] for u in G.nodes_iter(): preds = nx.preferential_attachment(G, [(u, v) for v in nx.non_neighbors(G, u)]) largest = heapq.nlargest(5, preds, key = lambda x: x[2]) for l in largest: selected_lines.append(l) subG = nx.Graph() for line in selected_lines: print line[0], line[1], line[2] if line[2]>1: subG.add_edge(line[0], line[1]) pos_subG = dict() for s in subG.nodes(): pos_subG[s] = pos[s] nx.draw_networkx_edges(subG, pos_subG, edge_color=’red’) 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 55 / 68
  • 56. 선호적 연결 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 56 / 68
  • 57. 선호적 연결 degree = nx.degree_centrality(G) nx.draw_networkx_nodes(G, pos, node_color=’yellow’, nodelist=degree.keys(), node_size=np.array(degree.values())*10000) nx.draw_networkx_edges(G, pos, alpha=0.2) nx.draw_networkx_labels(G, pos, font_size=20); selected_lines = [] for u in G.nodes_iter(): preds = nx.preferential_attachment(G, [(u, v) for v in nx.non_neighbors(G, u)]) largest = heapq.nlargest(5, preds, key = lambda x: x[2]) for l in largest: selected_lines.append(l) subG = nx.Graph() for line in selected_lines: print line[0], line[1], line[2] if line[2]>1: subG.add_edge(line[0], line[1]) pos_subG = dict() for s in subG.nodes(): pos_subG[s] = pos[s] nx.draw_networkx_edges(subG, pos_subG, edge_color=’red’) 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 57 / 68
  • 58. 선호적 연결 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 58 / 68
  • 59. NetworkX의 Link Prediction 함수들 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 59 / 68
  • 60. LPmade https://github.com/rlichtenwalter/LPmade 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 60 / 68
  • 61. 데모 matplotlib ipython과 d3.js 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 61 / 68
  • 62. ipython과 d3.js from IPython.display import display, HTML 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 62 / 68
  • 63. d3.js (Data-Driven Documents) 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 63 / 68
  • 64. ipython에서 파일 쓰기 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 64 / 68
  • 65. ipython에서 d3.js 가동하기 코드 https://goo.gl/LpxsKc 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 65 / 68
  • 66. ipython과 d3.js edges = d3_graph(G) make_html_graph(edges, 1000, 500) # make_html_graph(edges) %%HTML <iframe src="d3.html" width=100% height=500 frameborder=0></iframe> Demo 화면 : http://i.imgur.com/FeQ9kii.gif 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 66 / 68
  • 67. 다시 한 번, 이번 TALK의 목적 1 데이터 조종의 자유로움 2 아이디어 구현의 자유로움 3 융합의 자유로움 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 67 / 68
  • 68. The End 김경훈 (UNIST) NetworkX with Link Prediction 2015년 8월 29일 68 / 68