データセットの紹介

Python 中級ネットワーク解析

Eric Ma

Data Carpentry instructor and author of nxviz package

データセットとケーススタディの紹介

  • 大学フォーラムの投稿データセット(6ヶ月分)
  • ノードの区分:学生、フォーラム
  • 本章の学習内容:
    • pandas DataFrameからグラフを構築する
    • 二部グラフの一部グラフ射影を計算する
    • 可視化
    • 時系列フィルタリングと分析
  • これまでに使用した関数の復習
Python 中級ネットワーク解析

DataFrameからグラフを作成する

df
   customers    products
0  customerA    product1
1  customerB    product2
...
G = nx.Graph()

G.add_nodes_from(df['products'], bipartite='products') G.add_nodes_from(df['customers'], bipartite='customers')
list(G.nodes())
['product1', 'customerC', 'product2', 'customerB', 'customerA']
list(G.edges())
[]
Python 中級ネットワーク解析

DataFrameからグラフを作成する

G.add_edges_from(zip(df['customers'], df['products']))

list(G.edges())
[('product1', 'customerC'), ('product1', 'customerA'), 
    ('customerC', 'product2'), ('product2', 'customerB')]
Python 中級ネットワーク解析

二部グラフの射影

cust_nodes = [n for n in G.nodes() if G.nodes[n]
                 ['bipartite'] == 'customers']

prod_nodes = [n for n in G.nodes() if G.nodes[n] ['bipartite'] == 'products']
prodG = nx.bipartite.projected_graph(G, nodes=prod_nodes) custG = nx.bipartite.projected_graph(G, nodes=cust_nodes)
list(prodG.nodes())
['product1', 'product2']
list(custG.nodes())
['customerC', 'customerB', 'customerA']
Python 中級ネットワーク解析

では、練習しましょう!

Python 中級ネットワーク解析

Preparing Video For Download...