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
| Metric | Formula | Interpretation |
|---|---|---|
| Accuracy | (TP+TN)/(TP+TN+FP+FN) | Overall correctness. |
| Precision | TP/(TP+FP) | How many predicted positives are correct. |
| Recall (Sensitivity) | TP/(TP+FN) | How many actual positives are captured. |
| F1‑Score | 2·(Precision·Recall)/(Precision+Recall) | Balance between precision and recall. |
| Specificity | TN/(TN+FP) | True negative rate. |