การวาด mosaic plot จาก confusion matrix
การคำนวณ performance matrix ด้วยตัวเองอาจสนุกดี แต่ถ้าต้องสร้าง confusion matrix หลายๆ โมเดล ก็คงน่าเบื่อไม่น้อย โชคดีที่เมธอด .pred_table() ช่วยคำนวณ confusion matrix ให้ได้โดยอัตโนมัติ
นอกจากนี้ ยังสามารถนำผลลัพธ์จาก .pred_table() มาแสดงเป็นภาพของ confusion matrix ได้ด้วยฟังก์ชัน mosaic()
churn และ mdl_churn_vs_relationship พร้อมใช้งานแล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การถดถอยเบื้องต้นด้วย statsmodels ใน Python
คำแนะนำการฝึกหัด
- Import ฟังก์ชัน
mosaic()จากstatsmodels.graphics.mosaicplot - สร้าง
conf_matrixโดยใช้เมธอด.pred_table()แล้วแสดงผลออกมา - วาด mosaic plot จาก confusion matrix
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Import mosaic from statsmodels.graphics.mosaicplot
____
# Calculate the confusion matrix conf_matrix
conf_matrix = ____
# Print it
print(conf_matrix)
# Draw a mosaic plot of conf_matrix
____
plt.show()