Skip to main content
Albero Academy

Confusion Matrix & ROC

See exactly where a classifier is right and wrong.

Classification8 min

Two diagnostic tools complete the picture. The confusion matrix shows the counts of every right/wrong combination; the ROC curve (and its AUC) summarises performance across all thresholds.

The confusion matrix

who got confused with whom
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
confusion_matrix(y_test, preds)
# rows = actual, cols = predicted:
# [[TN, FP],
# [FN, TP]]
ConfusionMatrixDisplay.from_estimator(model, X_test, y_test)

ROC & AUC

threshold-independent performance
from sklearn.metrics import roc_auc_score, RocCurveDisplay
roc_auc_score(y_test, model.predict_proba(X_test)[:, 1])
RocCurveDisplay.from_estimator(model, X_test, y_test)
# AUC: 1.0 = perfect, 0.5 = random guessing

Key takeaways

  1. 01The confusion matrix shows counts of TN/FP/FN/TP — exactly which errors occur.
  2. 02It reveals the trade-off between false positives and false negatives.
  3. 03The ROC curve plots true- vs false-positive rate across thresholds.
  4. 04AUC is a threshold-independent score (0.5 random, 1.0 perfect) for comparing classifiers.

Finished this chapter?

Mark it complete to track your progress through Scikit-learn.