04.06 Lesson 6 of 16

1.2 h

Classification 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

Exercise

Calculate metrics under two thresholds

Use validation probabilities to compare a default threshold with one chosen for a stated recall or precision target.

  1. Calculate the confusion matrix and report precision, recall, specificity and F1.
  2. Calculate ROC-AUC and average precision from continuous probability scores.
  3. Plot or inspect a precision-recall curve.
  4. Compare threshold 0.5 with one alternative using validation data only.
  5. Write which error type matters most and justify the selected threshold.
Done when

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

2 links
  1. 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.

  2. 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

2 questions
  1. Question 1

    What is the difference between precision and recall?

  2. Question 2

    When can average precision be more informative than accuracy?

Completion check

Move on when

You can calculate and interpret threshold-dependent and ranking metrics, then justify a threshold from validation data.

Quick find

Search Michi

Type to search every stage, section, unit, topic and resource.

Enter opens the first result Esc closes

Reference

Keyboard shortcuts

n
Continue to the first unit not passed
j / k
Next / previous unit
1 2 3
Toggle learned, practised, passed
/
Open search
?
Show this help
Esc
Close open panels