29 / 90

Day 29: Evaluation — splits, leakage, and metrics

Separate training from evaluation: hold out validation and test data, exclude leakage, compare against honest baselines, and read loss, accuracy, and perplexity with distribution shift in mind.

Mathematics & Algorithmic Foundations 480 active minutes (8 hours focused study)
01 120 min

Train, validation, and test: fixing the comparison

Assistance allowed only after prediction and observed evidence are recorded.

Prerequisites

Day 28 statistics; the prediction-review routine.

Learning Objective

Explain the role of train/validation/test splits in evaluation and why the test set is read once; fix the evaluation protocol before any tuning begins.

Instructions

Evaluation answers 'does it generalize?' using data the model never trained on. The training split fits parameters; the validation split guides choices (which model, which settings); the test split is the final, untouched read. With 1,000 examples a 60/20/20 split gives 600 train, 200 validation, 200 test. Comparisons are only valid when every candidate is scored on the same split with the same metric — fix that protocol before tuning, not after seeing results.

Practice & Prediction Log

A learner has 1,000 labeled examples. (a) Allocate train/validation/test at 60/20/20. (b) Model M1 was selected after 40 trials scored on the test set — name the protocol violation and its consequence. (c) State what must be identical before M1 and M2 scores can be compared.

Independent Mastery Criterion

Learner states each split's role in evaluation, names the test-reuse violation, and writes the fixed-protocol checklist before any tuning.

Authoritative Source Resources & Provenance

linking CC BY-SA 4.0 (book text) / modified MIT (sample code) share-alike

Dive into Deep Learning (d2l.ai)

Author: Aston Zhang, Zachary C. Lipton, Mu Li, Alexander J. Smola | Original Source Link ↗

Relevant Section / Range: Section: Model Selection, Underfitting, and Overfitting

Verified Version & Date: Current online edition (Verified: 2026-10-30)

Selection Rationale:

Primary open reference tying evaluation discipline (model selection, underfitting, overfitting) and optimization algorithms (gradient descent, minibatch) to the rest of the curriculum.

Source Prerequisites:

Linear algebra, calculus, and probability at the Days 19-28 level.

Safe Fallback (Offline Resilience):

All required formulas and worked numbers are reproduced as original explanations; the book is further reading.

Compared Candidate Sources & Selection Analysis (2)
Deep Learning (Goodfellow, Bengio, Courville) ↗ compared_alternative [MIT Press; free HTML for reading, all rights reserved]

Detailed treatment of optimization difficulties (chapter 8) including saddle points and plateaus; all-rights-reserved text kept as a linking-only alternative.

fast.ai: Practical Deep Learning for Coders ↗ compared_alternative [Course site copyright / Apache-2.0 (fastai code)]

Strong practitioner framing, but organized around the fastai library and video lessons rather than self-contained mathematics.

linking CC BY 4.0

Google Machine Learning Crash Course

Author: Google for Developers | Original Source Link ↗

Relevant Section / Range: Modules: Training and Test Sets; Validation

Verified Version & Date: Current online edition (Verified: 2026-10-30)

Selection Rationale:

Industrial, beginner-legible treatment of training/test splitting and overfitting; complements d2l.ai's mathematical framing.

Source Prerequisites:

Basic algebra; short self-contained modules.

Safe Fallback (Offline Resilience):

Split discipline, leakage rules, and metric definitions are fully explained inside the lesson; the course is further reading.

Compared Candidate Sources & Selection Analysis (2)
Dive into Deep Learning (d2l.ai) ↗ compared_selected_for_day29 [CC BY-SA 4.0 (book text) / modified MIT (sample code)]

Co-primary: deeper mathematical coverage of model selection, generalization, and optimization for the mathematics-track capstone.

scikit-learn: Model Evaluation documentation ↗ compared_alternative [BSD-3-Clause]

Normative reference once learners call sklearn; kept as an alternative because these days teach evaluation protocol before library usage.

02 120 min

Baselines and data leakage

Independent Mastery Check (no AI assistance).

Prerequisites

Activity 29-01; no AI assistance in this block.

Learning Objective

Compute a trivial baseline and detect at least two leakage mechanisms that make an evaluation report a fabricated success.

Instructions

A baseline is the cheapest honest predictor: for classification, the majority class. If 900 of 1,000 examples are class 0, always predicting class 0 scores 0.90 — any model is judged against 0.90, not 0.0. Leakage is information flowing from evaluation data into training: normalization statistics computed on all rows before splitting, duplicated rows crossing the split, or a feature derived from the label. Each inflates the evaluation without real skill.

Practice & Prediction Log

(a) Dataset: 1,000 examples, 900 in class 0 — what is the majority baseline? A model reports 0.92: what is the real improvement? (b) A pipeline standardizes features using the mean of all 1,000 rows, then splits 60/20/20 — is the 0.92 score trustworthy, and why? (c) 50 test rows also appear (duplicated) inside the 600-row training set — what happens to the evaluation?

Independent Mastery Criterion

Baseline computed, at least two leakage mechanisms named with the correct fixes (fit-on-train-only, deduplicate, drop label-derived features), and the learner reports the honest lower number rather than the inflated one.

Authoritative Source Resources & Provenance

linking CC BY-SA 4.0 (book text) / modified MIT (sample code) share-alike

Dive into Deep Learning (d2l.ai)

Author: Aston Zhang, Zachary C. Lipton, Mu Li, Alexander J. Smola | Original Source Link ↗

Relevant Section / Range: Section: Model Selection, Underfitting, and Overfitting; generalization discussion

Verified Version & Date: Current online edition (Verified: 2026-10-30)

Selection Rationale:

Primary open reference tying evaluation discipline (model selection, underfitting, overfitting) and optimization algorithms (gradient descent, minibatch) to the rest of the curriculum.

Source Prerequisites:

Linear algebra, calculus, and probability at the Days 19-28 level.

Safe Fallback (Offline Resilience):

All required formulas and worked numbers are reproduced as original explanations; the book is further reading.

Compared Candidate Sources & Selection Analysis (2)
Deep Learning (Goodfellow, Bengio, Courville) ↗ compared_alternative [MIT Press; free HTML for reading, all rights reserved]

Detailed treatment of optimization difficulties (chapter 8) including saddle points and plateaus; all-rights-reserved text kept as a linking-only alternative.

fast.ai: Practical Deep Learning for Coders ↗ compared_alternative [Course site copyright / Apache-2.0 (fastai code)]

Strong practitioner framing, but organized around the fastai library and video lessons rather than self-contained mathematics.

linking CC BY 4.0

Google Machine Learning Crash Course

Author: Google for Developers | Original Source Link ↗

Relevant Section / Range: Modules: Overfitting; Generalization

Verified Version & Date: Current online edition (Verified: 2026-10-30)

Selection Rationale:

Industrial, beginner-legible treatment of training/test splitting and overfitting; complements d2l.ai's mathematical framing.

Source Prerequisites:

Basic algebra; short self-contained modules.

Safe Fallback (Offline Resilience):

Split discipline, leakage rules, and metric definitions are fully explained inside the lesson; the course is further reading.

Compared Candidate Sources & Selection Analysis (2)
Dive into Deep Learning (d2l.ai) ↗ compared_selected_for_day29 [CC BY-SA 4.0 (book text) / modified MIT (sample code)]

Co-primary: deeper mathematical coverage of model selection, generalization, and optimization for the mathematics-track capstone.

scikit-learn: Model Evaluation documentation ↗ compared_alternative [BSD-3-Clause]

Normative reference once learners call sklearn; kept as an alternative because these days teach evaluation protocol before library usage.

03 120 min

Metrics and distribution shift

Assistance allowed only after prediction and observed evidence are recorded.

Prerequisites

Activity 29-02; record predictions first.

Learning Objective

Read accuracy, cross-entropy loss, and perplexity as the same evaluation evidence at different resolutions, and diagnose a score drop caused by distribution shift rather than model failure.

Instructions

Accuracy counts right answers; cross-entropy (the mean −ln p assigned to the correct label) also prices confidence — p = 0.9 costs 0.105, p = 0.5 costs 0.693, p = 0.1 costs 2.303. Perplexity is exp(mean cross-entropy): the effective number of equally likely choices — a model always assigning p = 0.5 to the right token has perplexity 2, and a uniform guesser over 4 options has perplexity 4. Distribution shift breaks the train≈test assumption: a detector trained on daytime photos evaluated at night faces a new evaluation of a new distribution, not automatically a model defect.

Practice & Prediction Log

(a) For correct-label probabilities [0.9, 0.8, 0.7, 0.6], compute the mean cross-entropy and the perplexity. (b) A model scores 18/20 = 0.90 accuracy on its test split but 11/20 on night-time photos — give two distinct explanations and the follow-up check for each. (c) Which perplexity is better, 2.0 or 10.0, and what does each mean?

Independent Mastery Criterion

Correct NLL/perplexity arithmetic, the accuracy-vs-loss distinction stated, and shift versus defect separated with a concrete check for each.

Authoritative Source Resources & Provenance

linking CC BY-SA 4.0 (book text) / modified MIT (sample code) share-alike

Dive into Deep Learning (d2l.ai)

Author: Aston Zhang, Zachary C. Lipton, Mu Li, Alexander J. Smola | Original Source Link ↗

Relevant Section / Range: Sections: Loss functions and cross-entropy; dataset shift discussion

Verified Version & Date: Current online edition (Verified: 2026-10-30)

Selection Rationale:

Primary open reference tying evaluation discipline (model selection, underfitting, overfitting) and optimization algorithms (gradient descent, minibatch) to the rest of the curriculum.

Source Prerequisites:

Linear algebra, calculus, and probability at the Days 19-28 level.

Safe Fallback (Offline Resilience):

All required formulas and worked numbers are reproduced as original explanations; the book is further reading.

Compared Candidate Sources & Selection Analysis (2)
Deep Learning (Goodfellow, Bengio, Courville) ↗ compared_alternative [MIT Press; free HTML for reading, all rights reserved]

Detailed treatment of optimization difficulties (chapter 8) including saddle points and plateaus; all-rights-reserved text kept as a linking-only alternative.

fast.ai: Practical Deep Learning for Coders ↗ compared_alternative [Course site copyright / Apache-2.0 (fastai code)]

Strong practitioner framing, but organized around the fastai library and video lessons rather than self-contained mathematics.

linking CC BY 4.0

Google Machine Learning Crash Course

Author: Google for Developers | Original Source Link ↗

Relevant Section / Range: Modules: Classification accuracy; static versus dynamic evaluation

Verified Version & Date: Current online edition (Verified: 2026-10-30)

Selection Rationale:

Industrial, beginner-legible treatment of training/test splitting and overfitting; complements d2l.ai's mathematical framing.

Source Prerequisites:

Basic algebra; short self-contained modules.

Safe Fallback (Offline Resilience):

Split discipline, leakage rules, and metric definitions are fully explained inside the lesson; the course is further reading.

Compared Candidate Sources & Selection Analysis (2)
Dive into Deep Learning (d2l.ai) ↗ compared_selected_for_day29 [CC BY-SA 4.0 (book text) / modified MIT (sample code)]

Co-primary: deeper mathematical coverage of model selection, generalization, and optimization for the mathematics-track capstone.

scikit-learn: Model Evaluation documentation ↗ compared_alternative [BSD-3-Clause]

Normative reference once learners call sklearn; kept as an alternative because these days teach evaluation protocol before library usage.

04 120 min

Assessment: design a valid small experiment

Independent Mastery Check (no AI assistance).

Prerequisites

Activities 29-01 through 29-03; independent, closed-book.

Learning Objective

Design a complete, honest evaluation for a tiny classification task and defend every choice.

Instructions

Scenario: 800 labeled examples, two candidate models, classes split 80/20. Design the evaluation end to end and write it as a protocol: splits with sizes, baseline, primary metric plus one supporting metric, leakage checks, when the test set is read, and how you would report a negative result. Work without AI assistance; the point is a defensible protocol, not a lucky number.

Practice & Prediction Log

Write the protocol for the 800-example task (suggested 480/160/160), including the majority baseline value, the metric you would report besides accuracy, the three leakage checks, and the sentence you would write if the fancy model only matches the baseline.

Independent Mastery Criterion

Protocol is complete and internally consistent, states baseline 0.80 and at least one non-accuracy metric, includes the three leakage checks and the single test read, and the negative-result sentence is written without euphemism.

Authoritative Source Resources & Provenance

linking CC BY-SA 4.0 (book text) / modified MIT (sample code) share-alike

Dive into Deep Learning (d2l.ai)

Author: Aston Zhang, Zachary C. Lipton, Mu Li, Alexander J. Smola | Original Source Link ↗

Relevant Section / Range: Section: Model Selection, Underfitting, and Overfitting

Verified Version & Date: Current online edition (Verified: 2026-10-30)

Selection Rationale:

Primary open reference tying evaluation discipline (model selection, underfitting, overfitting) and optimization algorithms (gradient descent, minibatch) to the rest of the curriculum.

Source Prerequisites:

Linear algebra, calculus, and probability at the Days 19-28 level.

Safe Fallback (Offline Resilience):

All required formulas and worked numbers are reproduced as original explanations; the book is further reading.

Compared Candidate Sources & Selection Analysis (2)
Deep Learning (Goodfellow, Bengio, Courville) ↗ compared_alternative [MIT Press; free HTML for reading, all rights reserved]

Detailed treatment of optimization difficulties (chapter 8) including saddle points and plateaus; all-rights-reserved text kept as a linking-only alternative.

fast.ai: Practical Deep Learning for Coders ↗ compared_alternative [Course site copyright / Apache-2.0 (fastai code)]

Strong practitioner framing, but organized around the fastai library and video lessons rather than self-contained mathematics.

linking CC BY 4.0

Google Machine Learning Crash Course

Author: Google for Developers | Original Source Link ↗

Relevant Section / Range: Modules: Training and Test Sets; Overfitting

Verified Version & Date: Current online edition (Verified: 2026-10-30)

Selection Rationale:

Industrial, beginner-legible treatment of training/test splitting and overfitting; complements d2l.ai's mathematical framing.

Source Prerequisites:

Basic algebra; short self-contained modules.

Safe Fallback (Offline Resilience):

Split discipline, leakage rules, and metric definitions are fully explained inside the lesson; the course is further reading.

Compared Candidate Sources & Selection Analysis (2)
Dive into Deep Learning (d2l.ai) ↗ compared_selected_for_day29 [CC BY-SA 4.0 (book text) / modified MIT (sample code)]

Co-primary: deeper mathematical coverage of model selection, generalization, and optimization for the mathematics-track capstone.

scikit-learn: Model Evaluation documentation ↗ compared_alternative [BSD-3-Clause]

Normative reference once learners call sklearn; kept as an alternative because these days teach evaluation protocol before library usage.