Artificial intelligence • Original RRTutors lesson
Confusion Matrices, Precision, Recall, F1, and ROC/PR Curves
Interpret classification results beyond accuracy, especially when classes are imbalanced.
Concept and explanation
A confusion matrix counts true and false positives and negatives. Precision asks how many positive predictions are correct; recall asks how many actual positives were found. F1 combines precision and recall at a threshold, while ROC and precision-recall curves compare thresholds. Calibration measures whether predicted probabilities match observed frequencies.
How to apply it
Report class prevalence, the selected operating threshold, uncertainty, and error rates for relevant groups.
Worked example
When only one case in a thousand is fraud, a classifier that predicts “not fraud” every time has high accuracy but no fraud-detection value.
Illustrative Python example
from sklearn.metrics import classification_report
print(classification_report(y_true, y_pred, zero_division=0))
Expected result
The report summarizes per-class precision, recall, and F1 for the chosen predictions.
Limitations and cautions
Metrics computed on a non-representative dataset or selected threshold can mislead deployment decisions.
Practice exercise
Construct a small confusion matrix and calculate precision and recall for the positive class.
Key takeaway: Choose metrics based on consequences, prevalence, and operating threshold.