AI Knowledge Base

Model Evaluation

Evaluating a supervised learning model is essential to understand its performance, diagnose issues, and compare against baselines. This guide covers the most common metrics, confusion matrix analysis, and a quick interactive calculator.

Confusion Matrix

A confusion matrix summarizes the counts of true positives (TP), true negatives (TN), false positives (FP) and false negatives (FN) for binary classification.

from sklearn.metrics import confusion_matrix
y_true = [0,1,0,1,0]
y_pred = [0,1,0,0,1]
cm = confusion_matrix(y_true, y_pred)
print(cm)

Key Metrics

MetricFormulaInterpretation
Accuracy(TP+TN)/(TP+TN+FP+FN)Overall correctness.
PrecisionTP/(TP+FP)How many predicted positives are correct.
Recall (Sensitivity)TP/(TP+FN)How many actual positives are captured.
F1‑Score2·(Precision·Recall)/(Precision+Recall)Balance between precision and recall.
SpecificityTN/(TN+FP)True negative rate.

Interactive Confusion Matrix Calculator

Further Reading