Data Mining Exercise 13
Confusion Matrix Solution From Given Problem
Confusion Matrix Solution From Given Problem
โจทย์
ให้ข้อมูล 10 แถว (A, B, C, Class) และกำหนดกฎทำนายว่า
- Predict Positive เมื่อ A=1 และ C=1
- นอกนั้นทำนาย Negative
ต้องการหา:
- Confusion matrix
- Precision, Recall, TPR, FPR, TPR/FPR, F-score
- วิจารณ์โมเดล
ข้อมูลจากภาพ
| Instance | A | B | C | Class (Actual) |
|---|---|---|---|---|
| 1 | 0 | 0 | 0 | + |
| 2 | 0 | 0 | 1 | - |
| 3 | 0 | 1 | 1 | - |
| 4 | 0 | 1 | 1 | - |
| 5 | 0 | 0 | 1 | + |
| 6 | 1 | 0 | 1 | + |
| 7 | 1 | 0 | 1 | - |
| 8 | 1 | 0 | 1 | - |
| 9 | 1 | 1 | 1 | + |
| 10 | 1 | 0 | 1 | + |
1) สร้างผลทำนายจากกฎ (A=1 และ C=1 -> Positive)
- Predict Positive: instance 6,7,8,9,10
- Predict Negative: instance 1,2,3,4,5
เทียบกับ Actual:
- TP: 6,9,10 -> 3
- FP: 7,8 -> 2
- TN: 2,3,4 -> 3
- FN: 1,5 -> 2
ตรวจสอบรวม: TP+FP+TN+FN = 3+2+3+2 = 10
2) Confusion Matrix
| Predicted Positive | Predicted Negative | |
|---|---|---|
| Actual Positive | TP = 3 | FN = 2 |
| Actual Negative | FP = 2 | TN = 3 |
3) คำนวณ Metrics
ให้
- TP=3, FP=2, TN=3, FN=2
Precision
Precision = TP/(TP+FP) = 3/(3+2) = 3/5 = 0.60
Recall
Recall = TP/(TP+FN) = 3/(3+2) = 3/5 = 0.60
TPR
TPR = Recall = TP/(TP+FN) = 0.60
FPR
FPR = FP/(FP+TN) = 2/(2+3) = 2/5 = 0.40
TPR/FPR
TPR/FPR = 0.60/0.40 = 1.50
F-score (F1)
F1 = 2*(PrecisionRecall)/(Precision+Recall) = 2(0.60*0.60)/(0.60+0.60) = 0.60
ดังนั้น F-score = 0.60
4) วิจารณ์โมเดล
- โมเดลให้ผลระดับปานกลาง (Precision=Recall=0.60)
- จับ positive ได้ 60% และพลาด positive 40% (FN=2 จาก positive จริง 5)
- มี false alarm พอสมควร (FPR=0.40)
- กฎ A=1 และ C=1 ค่อนข้างหยาบ เพราะแยกไม่ได้ว่าบางเคสที่เข้าเงื่อนไขเป็นคลาสลบ (instance 7,8)
สรุป: โมเดลนี้พอใช้ได้เป็น baseline แต่ยังควรปรับกฎ/เพิ่มเงื่อนไขเพื่อลด FP และ FN