Confusion Matrix
Study guide: Exam MAS-II
A Confusion Matrix is a table that cross-tabulates the actual class of each observation against the class a classifier predicts for it, at a chosen threshold. It counts the true positives (TP), false negatives (FN), false positives (FP) and true negatives (TN):
| Predicted positive | Predicted negative | Total | |
|---|---|---|---|
| Actual positive | TP | FN | P |
| Actual negative | FP | TN | N |
| Total | P^* |
N^* |
T |
A true positive is an actual positive flagged positive, a false positive an actual negative flagged positive, and a false negative an actual positive not flagged. Every classification measure is a ratio of these counts.
Sensitivity and specificity
The sensitivity, or true positive rate, is the proportion of actual positives classified as positive:
\text{Sensitivity} = \frac{TP}{TP + FN}
The specificity, or true negative rate, is the proportion of actual negatives classified as negative:
\text{Specificity} = \frac{TN}{TN + FP}
The false positive rate is the proportion of actual negatives flagged positive, FP/(FP + TN) = 1 - specificity. Sensitivity is also called recall or power, and the false positive and false negative rates are the Type I and Type II error rates.
On 1,000 claims, 60 are fraudulent. A model flags 90 claims, of which 45 are fraudulent. What are its sensitivity and specificity?
TP = 45,FP = 90 - 45 = 45,FN = 60 - 45 = 15,TN = 1000 - 45 - 45 - 15 = 895.- Sensitivity is
45/60 = 75.0\%.- Specificity is
895/940 = 95.2\%, so the false positive rate is4.8\%.
Precision and accuracy
The precision, or positive predicted value, is the share of flagged cases that are actually positive:
\text{Precision} = \frac{TP}{TP + FP}
The accuracy is the share of all cases classified correctly:
\text{Accuracy} = \frac{TP + TN}{T}
The error rate is 1 - accuracy, (FN + FP)/T.
For the fraud model above, what are the precision and accuracy?
- Precision is
45/90 = 50.0\%.- Accuracy is
(45 + 895)/1000 = 94.0\%.
Choice of threshold
The matrix depends on the threshold applied to the predicted probability. Lowering the threshold flags more cases, which raises sensitivity and lowers specificity. When missing a positive is costly and positives are rare, a lower threshold is preferred, because the cost of the extra false-positive investigations is small against the cost of a missed positive. The ROC curve shows every threshold at once.
Accuracy under class imbalance In the fraud example, flagging no claims at all scores
940/1000 = 94.0\%accuracy, the same as the model, with a sensitivity of zero. When one class is rare, judge a classifier by its sensitivity and specificity, not its accuracy.