การติดป้ายกำกับ node
ในแบบฝึกหัดนี้ คุณจะติดป้ายกำกับ node ในเครือข่าย โดยจะมี dataframe ชื่อ customers ที่มี customer ID เดียวกับใน network ลูกค้าแต่ละรายมีสถานะระบุว่า churn หรือไม่ แทนด้วยค่า 1 และ 0 ตามลำดับ
จากนั้นจะเพิ่มสถานะ churn ให้กับ node ใน network และแสดงผลด้วยภาพ
โปรดทราบว่า network สามารถมีได้ทั้ง node attribute และ edge attribute
Node attribute แทนด้วยฟังก์ชัน V() (ย่อมาจาก vertex) และ edge attribute แทนด้วยฟังก์ชัน E()
Node attribute ของ churn network คือ V(network)
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์เชิงพยากรณ์โดยใช้ข้อมูลเครือข่ายใน R
คำแนะนำการฝึกหัด
- ตรวจสอบ dataframe
customersด้วยฟังก์ชันhead() - ใช้ฟังก์ชัน
table()เพื่อนับจำนวนผู้ที่ churn และไม่ churn ใน dataframecustomers - ใช้ฟังก์ชัน
V()เพื่อเพิ่ม node attribute ชื่อchurnให้กับ network แล้วกำหนดคอลัมน์churnจาก dataframecustomersให้กับ attribute นั้น - แสดงผล network โดยเรียกใช้ฟังก์ชัน
plot()
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Inspect the customers dataframe
___(customers)
# Count the number of churners and non-churners
table(customers$___)
# Add a node attribute called churn
___(network)$___ <- customers$churn
# Visualize the network
___(___, vertex.label = NA, edge.label = NA,
edge.color = 'black', vertex.size = 2)