notesonly.in

One notebook for every subject — open it anywhere.

Log in

Model Evaluation: Cross-Validation and Metrics For students.

Building a model is only half the job; proving it works is the other half. Model evaluation measures how well a trained model performs on data it never saw, using the right metrics. A model scoring 99 percent on training data but 60 percent on new data has memorized, not learned — and only honest evaluation reveals the difference.

Evaluation matters because models make real decisions: approving loans, flagging fraud, diagnosing illness. The wrong metric hides catastrophic failure — a fraud detector labeling every transaction "legitimate" scores 99.9 percent accuracy while catching zero fraud. Cross-validation and the right metrics turn model selection from guesswork into engineering.

Key Concepts

  • Train/validation/test split: training data teaches, validation data tunes settings, and the test set — used once — gives the honest final score.
  • K-fold cross-validation: split data into k parts, train on k−1, test on the rest, rotate k times, average the scores.
  • Confusion matrix: a 2 by 2 table of true positives (TP), true negatives (TN), false positives (FP), false negatives (FN).
  • Accuracy: the fraction of all predictions that are correct.
  • Precision: TP divided by (TP + FP) — of flagged items, how many truly are positive.
  • Recall: TP divided by (TP + FN) — of truly positive items, how many were caught.
  • F1 score: the harmonic mean of precision and recall, balancing the two.
  • Overfitting vs underfitting: too-complex models memorize noise; too-simple ones miss the pattern.

Formulas

  • Accuracy = (TP + TN) divided by (TP + TN + FP + FN). Simple overall correctness; misleading on imbalanced data.
  • Precision = TP divided by (TP + FP): few false alarms. Recall = TP divided by (TP + FN): few missed cases.
  • F1 = 2 times precision times recall, divided by (precision + recall). The harmonic mean punishes being good at only one of the two. All are unitless ratios between 0 and 1, assuming a binary problem with a defined positive class.

Worked Example

A disease-screening model tested on 200 patients gives TP = 80, FP = 20, FN = 10, TN = 90. Totals check: 80 + 20 + 10 + 90 = 200. Accuracy = (80 + 90) divided by 200 = 170 divided by 200 = 85 percent. Precision = 80 divided by 100 = 80 percent — when it raises an alarm it is right 4 times out of 5. Recall = 80 divided by 90, about 88.9 percent — it catches most sick patients, missing 10. F1 = 2 times 0.80 times 0.889, divided by 1.689 = 1.422 divided by 1.689, about 0.842. With 1000 patients and 5-fold CV, each round trains on 800 and validates on 200; averaging the five scores uses every patient exactly once as validation.

Common Misconceptions

  • Accuracy is the only metric that matters. On imbalanced data it lies; precision, recall, and F1 tell the real story.
  • Cross-validation replaces the test set. CV tunes and compares models; a final untouched test set is still the report card.
  • More metrics always help. Report the metrics matching the problem's costs — missing a disease versus false alarms — not every number available.

Real-World Applications

  • Competitions: leaderboards rank models by chosen metrics on hidden data.
  • Medical screening: recall is optimized so few sick patients are missed.
  • Fraud detection: precision-recall trade-offs set manual review volumes.
  • A/B testing: challenger models must beat champions on offline metrics first.

Model evaluation means measuring on unseen data: split train, validation, and test; cross-validate for stable estimates; and choose metrics — accuracy, precision, recall, F1 — matching each mistake's real cost. A model is only as trustworthy as its evaluation.