Skip to main content
Albero Academy

Model Evaluation & Next Steps

Measure a model honestly — the right metrics, overfitting, cross-validation — and what it takes to ship one.

Chapter 4Data Science15 min readBeginner friendly
  • #Data Science
  • #Evaluation
  • #Metrics

A model is only as good as its evaluation. This final chapter is about measuring performance honestly — the metric traps that fool beginners, why models that ace training can fail in the wild, and what happens after a model works.

Beyond accuracy

Accuracy alone lies on imbalanced data. If 98% of transactions are legitimate, a model that predicts "legit" every time is 98% accurate and completely useless — it never catches fraud. You need metrics that account for the errors that matter:

Classification metrics

MetricAnswers
PrecisionOf predicted positives, how many were right?
RecallOf actual positives, how many did we catch?
F1 scoreThe balance of precision and recall
Confusion matrixThe full breakdown of right/wrong per class
a fuller evaluation
from sklearn.metrics import classification_report, confusion_matrix
preds = model.predict(X_test)
print(confusion_matrix(y_test, preds))
print(classification_report(y_test, preds)) # precision, recall, F1 per class

Overfitting

A model overfits when it memorises the training data — including its noise — instead of learning the general pattern. The tell: great on training, poor on the test set. The opposite, underfitting, is too simple to capture the pattern at all:

  • Overfit → gather more data, simplify the model, or add regularisation.
  • Underfit → use a richer model or better features.

Cross-validation

A single train/test split can get lucky. K-fold cross-validation splits the data k ways, trains and tests k times, and averages — a far more reliable estimate of real-world performance:

cross-validation
from sklearn.model_selection import cross_val_score
scores = cross_val_score(model, X, y, cv=5) # 5 folds
print(f"Mean accuracy: {scores.mean():.2%} (+/- {scores.std():.2%})")

Shipping a model

A model in a notebook helps no one. Getting value from it means:

  • Save the trained model and serve predictions behind an API (see the Node.js / AWS courses).
  • Monitor it — real-world data drifts, so performance decays over time.
  • Retrain on fresh data periodically.

Practice

Re-evaluate your model from Chapter 3 with a classification_report and confusion matrix instead of raw accuracy. Run 5-fold cross-validation. If training accuracy far exceeds test accuracy, note that it's overfitting and one thing you'd try.

Key takeaways

  1. 01Accuracy misleads on imbalanced data — use precision, recall, F1 and the confusion matrix.
  2. 02Choose the metric by which error is more costly (recall vs precision).
  3. 03Overfitting = memorising training data (great train, poor test); underfitting = too simple.
  4. 04K-fold cross-validation gives a more reliable performance estimate than one split.
  5. 05A useful model is served, monitored for drift, and retrained on fresh data.