Confusion Matrix
ELI5 - The Vibe Check
A confusion matrix is a little table that stops your model from lying to you with a single accuracy number. It breaks every prediction down into four buckets: correctly said yes, correctly said no, wrongly said yes, wrongly said no, so you can see exactly what kind of mistakes it's making, not just how often.
Real Talk
A confusion matrix is a table that cross-tabulates a classification model's predicted labels against the actual labels, breaking results into true positives, true negatives, false positives, and false negatives. It's the raw material that precision, recall, and F1 score are calculated from, and it exposes lopsided error patterns that a single accuracy figure hides.
Show Me The Code
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_true, y_pred)
# [[TN, FP],
# [FN, TP]]
print(cm)
When You'll Hear This
"The accuracy looked great until we checked the confusion matrix and saw it was calling everything 'not fraud'." / "Plot the confusion matrix so we can see which classes the model actually confuses."
Related Terms
Class Imbalance
Class imbalance is when your fraud detector trains on data where 99.9% of transactions are totally normal, so it can hit 99.
Classification
Classification is teaching an AI to sort things into categories. Is this email spam or not? Is this image a cat, dog, or bird?
F1 Score
The F1 Score is the balanced average of precision and recall — a single number that captures both.
Precision
Precision asks: 'Of all the times the AI said YES, how often was it actually right?
Recall
Recall asks: 'Of all the actual YES cases in the world, how many did the AI catch?' High recall means the model finds almost everything it should.