แนะนำชุดข้อมูล

การวิเคราะห์เครือข่ายระดับกลางใน Python

Eric Ma

Data Carpentry instructor and author of nxviz package

แนะนำชุดข้อมูลและกรณีศึกษา

  • ชุดข้อมูลโพสต์ในฟอรัมมหาวิทยาลัย ช่วง 6 เดือน
  • การแบ่งโหนด: นักศึกษา, ฟอรัม
  • กิจกรรมในบทนี้:
    • สร้างกราฟจาก pandas DataFrame
    • คำนวณ unipartite projections ของกราฟไบพาร์ไทต์
    • การแสดงภาพกราฟ
    • การกรองและวิเคราะห์อนุกรมเวลา
    • ทบทวนฟังก์ชันที่เคยใช้
การวิเคราะห์เครือข่ายระดับกลางใน 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

Bipartite projections

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