Confusion matrices
Confusion matrix เป็นจุดเริ่มต้นที่ดีในการสำรวจความแม่นยำของโมเดล เนื่องจากให้ค่าที่จำเป็นสำหรับการคำนวณ metrics ต่าง ๆ ได้หลากหลาย ทั้ง sensitivity, specificity และ F1-score
สมมติว่าสร้างโมเดล classification เพื่อทำนายว่าบุคคลมีแขนหักหรือไม่จากภาพ X-ray บนชุดข้อมูลทดสอบ ได้ confusion matrix ดังนี้
| Prediction: 0 | Prediction: 1 | |
|---|---|---|
| Actual: 0 | 324 (TN) | 15 (FP) |
| Actual: 1 | 123 (FN) | 491 (TP) |
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การตรวจสอบความถูกต้องของโมเดลใน Python
คำแนะนำการฝึกหัด
- ใช้ confusion matrix เพื่อคำนวณ accuracy โดยรวม
- ใช้ confusion matrix เพื่อคำนวณ precision และ recall
- ใช้คำสั่ง print ทั้งสามเพื่อแสดงค่า accuracy แต่ละค่า
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Calculate and print the accuracy
accuracy = (____ + ____) / (953)
print("The overall accuracy is {0: 0.2f}".format(accuracy))
# Calculate and print the precision
precision = (____) / (____ + ____)
print("The precision is {0: 0.2f}".format(precision))
# Calculate and print the recall
recall = (____) / (____ + ____)
print("The recall is {0: 0.2f}".format(recall))