Skip to main content

Model Evaluation Metrics

Choose the metric that matches the cost of mistakes, not just the default.

Regression​

MetricMeaning
MAEAverage absolute error; robust, easy to explain
MSE / RMSEPenalises large errors more; RMSE has the target's units
R²Share of variance explained (1 is perfect)

Classification: the confusion matrix​

Predicted + Predicted -
Actual + TP FN
Actual - FP TN
MetricFormulaUse when
Accuracy(TP + TN) / totalClasses are balanced
PrecisionTP / (TP + FP)False alarms are costly (spam filter)
Recall (sensitivity)TP / (TP + FN)Misses are costly (disease screening)
F12PR / (P + R)Balance precision and recall
ROC-AUCArea under TPR vs FPR curveRanking quality across thresholds

Why accuracy can mislead​

If 99% of transactions are legitimate, a model that always predicts "legitimate" has 99% accuracy but catches no fraud. Use precision, recall, F1 or PR-AUC on imbalanced data.

from sklearn.metrics import classification_report, confusion_matrix

pred = clf.predict(X_test)
print(confusion_matrix(y_test, pred))
print(classification_report(y_test, pred))

Splitting strategies​

StrategyWhen
Train / validation / testPlenty of data
k-fold cross-validationLimited data
Stratified splitImbalanced classes
Time-based splitTime series (never shuffle across time)

Diagnosing a model​

SymptomLikely causeTry
High train and test errorUnderfittingMore features, a more flexible model
Low train, high test errorOverfittingMore data, regularisation, simpler model
Good offline, bad in productionData drift or leakageMonitor inputs, fix the pipeline