Giới thiệu bộ dữ liệu

Phân tích mạng nâng cao với Python

Eric Ma

Data Carpentry instructor and author of nxviz package

Giới thiệu bộ dữ liệu & nghiên cứu tình huống

  • Bộ dữ liệu bài đăng trên diễn đàn đại học, 6 tháng
  • Phân hoạch nút: sinh viên, diễn đàn
  • Hoạt động trong chương:
    • Xây dựng đồ thị từ pandas DataFrame
    • Tính chiếu đơn phần của đồ thị hai phần
    • Trực quan hóa
    • Lọc & phân tích chuỗi thời gian
  • Ôn lại các hàm đã dùng
Phân tích mạng nâng cao với Python

Đồ thị từ 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())
[]
Phân tích mạng nâng cao với Python

Đồ thị từ DataFrame

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

list(G.edges())
[('product1', 'customerC'), ('product1', 'customerA'), 
    ('customerC', 'product2'), ('product2', 'customerB')]
Phân tích mạng nâng cao với Python

Chiếu đồ thị hai phần

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']
Phân tích mạng nâng cao với Python

Hãy luyện tập!

Phân tích mạng nâng cao với Python

Preparing Video For Download...