Natural Language Processing · TEE · papers
Q6b · Classification evaluation including ROC/AUC
2023-01-30 · re-exam · recovered AI paper
Previous examination · complete worked answers
Answer
Evaluation compares predicted results with known answers. A true positive is a correctly predicted positive; a false positive is a negative item predicted positive; a false negative is a missed positive; a true negative is a correctly rejected negative.
\text{Precision}=\frac{TP}{TP+FP}\text{Recall}=\frac{TP}{TP+FN}F_1=\frac{2PR}{P+R}=\frac{2TP}{2TP+FP+FN}\text{Accuracy}=\frac{TP+TN}{TP+TN+FP+FN}Precision asks how many predicted positives were correct. Recall asks how many actual positives were found. F1 balances them by a harmonic mean. If a denominator is zero, state the convention rather than dividing by zero.
Example 1 · evaluate a classifier
A binary text classifier gives TP=6, FP=2, FN=4, TN=8. Compute precision, recall, F1 and accuracy.
TP=6; FP=2; FN=4; TN=8.
To findFour evaluation measures.
Formula and why it applies
P=\frac{TP}{TP+FP},\quad R=\frac{TP}{TP+FN}F_1=\frac{2TP}{2TP+FP+FN},\quad A=\frac{TP+TN}{TP+FP+FN+TN}Use predicted positives in precision, actual positives in recall, and all examples in accuracy.
Solution
Step 1. Precision
P=\frac{6}{6+2}=0.750000Step 2. Recall
R=\frac{6}{6+4}=0.600000Step 3. F1
F_1=\frac{12}{12+2+4}=0.666667Step 4. Accuracy
A=\frac{6+8}{6+2+4+8}=0.700000Example 2 · evaluate a classifier
A binary text classifier gives TP=9, FP=3, FN=1, TN=7. Compute precision, recall, F1 and accuracy.
TP=9; FP=3; FN=1; TN=7.
To findFour evaluation measures.
Formula and why it applies
P=\frac{TP}{TP+FP},\quad R=\frac{TP}{TP+FN}F_1=\frac{2TP}{2TP+FP+FN},\quad A=\frac{TP+TN}{TP+FP+FN+TN}Use predicted positives in precision, actual positives in recall, and all examples in accuracy.
Solution
Step 1. Precision
P=\frac{9}{9+3}=0.750000Step 2. Recall
R=\frac{9}{9+1}=0.900000Step 3. F1
F_1=\frac{18}{18+3+1}=0.818182Step 4. Accuracy
A=\frac{9+7}{9+3+1+7}=0.800000Example 3 · evaluate a classifier
A binary text classifier gives TP=4, FP=0, FN=4, TN=12. Compute precision, recall, F1 and accuracy.
TP=4; FP=0; FN=4; TN=12.
To findFour evaluation measures.
Formula and why it applies
P=\frac{TP}{TP+FP},\quad R=\frac{TP}{TP+FN}F_1=\frac{2TP}{2TP+FP+FN},\quad A=\frac{TP+TN}{TP+FP+FN+TN}Use predicted positives in precision, actual positives in recall, and all examples in accuracy.
Solution
Step 1. Precision
P=\frac{4}{4+0}=1.000000Step 2. Recall
R=\frac{4}{4+4}=0.500000Step 3. F1
F_1=\frac{8}{8+0+4}=0.666667Step 4. Accuracy
A=\frac{4+12}{4+0+4+12}=0.800000ROC and AUC
\mathrm{TPR}=\frac{TP}{TP+FN},\qquad\mathrm{FPR}=\frac{FP}{FP+TN}A classifier produces scores. Sweep the decision threshold; at each threshold calculate TPR and FPR. Plot FPR horizontally and TPR vertically. AUC is the area under that curve, equivalently the probability that a randomly chosen positive has a higher score than a randomly chosen negative (ties conventionally contribute half). AUC1 is perfect ranking;0.5 is chance ranking. This evaluates ranking over thresholds, not the accuracy at one threshold.
| Illustrative threshold | TPR | FPR |
|---|---|---|
| Above all scores | 0 | 0 |
| Middle threshold | 0.8 | 0.2 |
| Below all scores | 1 | 1 |
For straight segments through (0,0),(.2,.8),(1,1), trapezoid area=.2×(0+.8)/2+.8×(.8+1)/2=.08+.72=.80. These points illustrate integration; they are not supplied exam data. Precision–recall may be more informative for rare positives.