Confusion Matrix ใช้วัดประสิทธิภาพของ Model

สิ่งแรกที่ทุกคนต้องรู้จัก Confusion Matrix เราจึงยกตัวอย่างตาราง cross-tabs 2×2 ขึ้นมา ระหว่าง prediction และ actual label การคำนวณ metrics ต่างๆจะใช้ตัวเลขในตารางนี้เป็นหลัก

Accuracy

เป็นวิธีวัดความแม่นยำ โดย ประกอบด้วย

True Positive (TP) = ทำนายจริง คำตอบจริง
True Negative (TN) = ทำนายไม่จริง คำตอบไม่จริง
False Positive (FP) = ทำนายจริง คำตอบไม่จริง
False Negative (FN) = ทำนายไม่จริง คำตอบจริง

ตารางด้านบนสรุปผลการทำนายอีเมล์ทั้งหมด N=100

Accuracy คือ metric ที่ใช้งานง่ายที่สุด บอกว่าโมเดลเราทำนายถูกทั้งหมดกี่ %

เราจะเขียนสูตรว่า accuracy = (TP + TN)/ N โดยค่า accuracy จะมีค่าอยู่ระหว่าง 0–1 ยิ่งเข้าใกล้ 1 แปลว่าโมเดลเราทำนายผลได้ดีมาก

จากตารางด้านบน accuracy = (20 + 50) / 100 = 70%

Precision

คือความน่าจะเป็นที่โมเดลทำนาย spam ถูกต้องจากการทำนาย spam ทั้งหมด 32 ครั้ง (20 + 12 ผลรวมแถวบนของ confusion matrix)

แทนค่าในสมการ precision = TP / (TP + FP) = 20 / (20 + 12) = 62.5%

Recall

คือความน่าจะเป็นที่โมเดลสามารถตรวจจับ spam จากจำนวน spam email ทั้งหมดในข้อมูลของเรา 38 ฉบับ (20 + 18 ผลรวมคอลั่มแรกของ confusion matrix)

แทนค่าในสมการ recall = TP / (TP + FN) = 20 / (20 + 18) = 52.6%

F1-Score

F1-Score คือค่าเฉลี่ยแบบ harmonic mean ระหว่าง precision และ recall

แทนค่าในสมการ F1 = 2 * ( (0.625 * 0.526) / (0.625 + 0.526) ) = 57.1%

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade