37. How to Check If Your ML Model Is Good
37.3 Confusion Matrix
Why. A confusion matrix shows the four buckets: true/false × positive/negative — so nobody argues from a single %
What. Rows = true class, columns = predicted class (sklearn default). You see true positives, false positives, true negatives, false negatives in one grid.
How.
Read the grid
- Print confusion_matrix(y_true, y_pred).
- Circle false negatives (missed fraud) and false positives (false alarms).
- Decide which error hurts your shop more.
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
y_true = [1, 1, 1, 0, 0, 0, 0, 0]
y_pred = [1, 1, 0, 1, 0, 0, 0, 0]
print(confusion_matrix(y_true, y_pred))
# Optional plot in Jupyter:
# ConfusionMatrixDisplay.from_predictions(y_true, y_pred)
Ravindra Bagale's Tip
Matrix whiteboard var draw kara ekda — numbers sticky hotat.