04.06 Lesson 6 of 16
1.2 hClassification Metrics & Decision Thresholds
Evaluate classifiers with confusion matrices, precision, recall, F1, ROC-AUC and average precision, especially when classes are imbalanced.
By the end of this lesson
You will be able to
- Define true positives, false positives, true negatives and false negatives.
- Explain precision, recall, specificity and F1.
- Distinguish ROC-AUC from average precision.
- Explain why accuracy can mislead under class imbalance.
Start from the confusion matrix
For a binary classifier, the confusion matrix counts true positives (TP), false positives (FP), true negatives (TN) and false negatives (FN). Precision is TP / (TP + FP): among predicted positives, how many were correct? Recall is TP / (TP + FN): among actual positives, how many were found? Specificity is TN / (TN + FP). F1 is the harmonic mean of precision and recall. Accuracy can look high when the majority class dominates, even if the model rarely finds the positive class.
from sklearn.metrics import classification_report, confusion_matrix
labels = classifier.predict(X_valid)
print(confusion_matrix(y_valid, labels))
print(classification_report(y_valid, labels, zero_division=0)) Ranking metrics and operating thresholds answer different questions
ROC-AUC measures how well scores rank positives above negatives across thresholds. The precision-recall curve focuses on positive-class retrieval and is often more informative when positives are rare. Average precision summarizes the precision-recall curve. These metrics do not select the business threshold for you. Use validation probabilities to choose a threshold that matches relative error costs or capacity, record that choice, then evaluate once on the untouched test data.
Apply what you learned
ExerciseCalculate metrics under two thresholds
Use validation probabilities to compare a default threshold with one chosen for a stated recall or precision target.
- Calculate the confusion matrix and report precision, recall, specificity and F1.
- Calculate ROC-AUC and average precision from continuous probability scores.
- Plot or inspect a precision-recall curve.
- Compare threshold 0.5 with one alternative using validation data only.
- Write which error type matters most and justify the selected threshold.
The analysis reports threshold-independent ranking metrics separately from threshold-dependent metrics and does not choose a threshold from test labels.
Free references
Study resources
- 01 Model Evaluation: Quantifying the Quality of Predictions Article
Read the classification metric sections for confusion matrices, precision/recall, F1, ROC-AUC and average precision.
- 02 ROC and AUC, Clearly Explained! Video
Watch this individual ROC/AUC explanation and note how changing the threshold changes the confusion matrix.
Check your understanding
Self-test
-
Question 1
What is the difference between precision and recall?
Precision measures how many predicted positives are correct. Recall measures how many actual positives the classifier finds. -
Question 2
When can average precision be more informative than accuracy?
When positives are uncommon and the priority is to understand how well the model retrieves positive examples across thresholds.
Completion check
Move on when
You can calculate and interpret threshold-dependent and ranking metrics, then justify a threshold from validation data.