Data Science

The Confusion Matrix Explained

Senior Data Analyst
May 9, 2026
5 min read

The Matrix

from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay

cm = confusion_matrix(y_test, predictions)

ConfusionMatrixDisplay(cm).plot()

Key Metrics

  • **Precision**: When I say "Yes," how often am I right?
  • **Recall**: Of all actual "Yes," how many did I catch?
  • **F1-Score**: Harmonic mean of Precision and Recall.
  • from sklearn.metrics import classification_report

    print(classification_report(y_test, predictions))

    *Day 130: Decision Trees.*

    Ready to put your knowledge into practice?

    Join SQL Mastery and learn through interactive exercises.