בתוך המעבדה בישראל (ישראל בירן)

Download Report

Transcript בתוך המעבדה בישראל (ישראל בירן)

‫הערכת טיב המודל‬
F-Measure, Kappa, Costs, MetaCost
‫ד"ר אבי רוזנפלד‬
‫הגדרות‬
‫מדד‬
‫‪Precision‬‬
‫‪Recall‬‬
‫‪F-Measure‬‬
‫‪Accuracy‬‬
‫נוסחה‬
‫משמעות‬
‫בכמה אחוזים דייקתי‬
‫בקטגוריה מסוימת (מתוך אלו )‪TP / (TP + FP‬‬
‫שאמרתי הם בקטגוריה)‬
‫בכמה אחוזים דייקתי בכלל‬
‫במופעים בקטגוריה‬
‫)‪TP / (TP + FN‬‬
‫‪2*precision*recall/ Harmonic mean of‬‬
‫‪precision+recall precision and recall‬‬
‫הדיוק הכללי‬
‫)הכול( ‪(TP + TN) /‬‬
Confusion matrix 1
Confusion matrix 2
P
N
P
N
P
20
10
P
10
20
N
30
90
N
15
105
FP
FN
Predicted
Precision (P) = 20 / 50 = 0.4
Recall (P) = 20 / 30 = 0.666
F-measure=2*.4*.666/1.0666=.5
Actual
Actual
False Positives / Negatives
Predicted
The Kappa Statistic
• Kappa measures relative improvement over random prediction
• Dreal / Dperfect = A (accuracy of the real model)
• Drandom / Dperfect= C (accuracy of a random model)
• Kappa Statistic = (A-C) / (1-C)
= (Dreal / Dperfect – Drandom / Dperfect ) / (1 – Drandom / Dperfect )
Remove Dperfect from all places
• (Dreal – Drandom) / (Dperfect – Drandom)
• Kappa = 1 when A = 1
• Kappa  0 if prediction is no better than random guessing
Aside: the Kappa statistic
• Two confusion matrix for a 3-class problem: real model (left) vs
random model (right)
Predicted
Predicted
b
c
a
total
a
88
10
2 100
b
14
40
6
60
c
18
10
12
40
total 120
60
20 200
Actual
Actual
a
b
total
a
60
30
b
36
18
6
60
c
24
12
4
40
total 120
60
• Number of successes: sum of values in diagonal (D)
• Kappa = (Dreal – Drandom) / (Dperfect – Drandom)
– (140 – 82) / (200 – 82) = 0.492
– Accuracy = 140/200 = 0.70
c
10 100
20 200
The kappa statistic – how to calculate
Drandom ?
Expected confusion matrix, E, for a
random model
Actual confusion matrix, C
b
c
a
total
a
88
10
2 100
b
14
40
6
60
c
18
10
12
40
total 120
60
20 200
Actual
Actual
a
a
b
?
c
total
100
b
60
c
40
total 120
60
20 200
100*120/200 = 60
Rationale: 100 actual values, 120/200 in
the predicted class, so random is:
100*120/200
‫‪Cost-Sensitive Learning‬‬
‫• מוסיפים עלות לכל סוג של סיווג‬
‫• בדרך כלל‪ ,‬אלגוריתמים לא מפרידים בין קטגוריות‬
‫• אבל יש ה‪-‬ר‪-‬ב‪-‬ה יישומים שזה חשוב‪:‬‬
‫– אבחון סרטן‬
‫– אבחון סיכונים (התקפות מחשב‪ ,‬זיוף‪ ,‬וכו')‬
Class Imbalance vs. Asymmetric
Misclassification costs
• Class Imbalance: one class occurs much more often than the
other
• Asymmetric misclassification costs: the cost of misclassifying
an example from one class is much larger than the cost of
misclassifying an example from the other class.
‫ שני המוסגים בדרך כלל באים ביחד‬:‫• לפי הניסיון שלי‬
‫• גם הפתרונות דומות‬
:‫• דוגמאות‬
MAJORITY CLASS‫– תוריד שורות מה‬
MINORITY CLASS‫– תוסיף שורות ל‬
METACOST -- MINORITY‫– תוסיף עלות ל‬
Making Classifier Balanced
• Baseline Methods
– Random over-sampling
– Random under-sampling
• Under-sampling Methods
–
–
–
–
–
Tomek links
Condensed Nearest Neighbor Rule
One-sided selection
CNN + Tomek links
Neighborhood Cleaning Rule
• Over-sampling Methods
– Smote
• Combination of Over-sampling method with Under-sampling method
– Smote + Tomek links
– Smote + ENN
Confusion matrix 2
Confusion matrix 1
P
N
P
N
P
20
10
P
10
20
N
30
90
N
15
105
FP
FN
Actual
Actual
???‫איזה מצב יותר טוב‬
Predicted
Predicted
Cost matrix
Error rate: 40/150
Cost: 30x1+10x2=50
P
N
P
0
2
N
1
0
Error rate: 35/150
Cost: 15x1+20x2=55
FN
MetaCost
• By wrapping a cost-minimizing procedure, “metalearning” stage, around the classifier
"‫• תתייחס לסוג הלמידה כ"קופצה שחורה‬
‫ ולהשפיע על התוצאות‬COST‫• אפשר לשנות את ה‬
:‫דוגמא‬
CRUISE CONTROL ‫מתי אנשים מפעילים‬
95
93
Overall Accuracy
91
89
87
85
All
83
Without
81
79
77
75
0
0.1
0.2
0.3
0.4
0.5
Recall of Minority Case
0.6
0.7
‫מתוך ‪WEKA‬‬
‫‪ Metacost‬בלי תוספת עלות‬
WEKA ‫מתוך‬
‫ עם עלות‬Metacost