Chapter 06 of 16: Check learning on new cases

Did it learn the task or memorize the cards?

Arun MalikSeriesAIFoundations
Table of Contents
Builds on chapter 5. Specific dependencies are in the concept map.

A student who has seen every answer on tomorrow's quiz may score perfectly. That result tells us little about the next quiz. A model can fool us in much the same way.

Keep some examples out of practice

A training set is the collection used to fit model parameters. A validation set is separate data used to guide development choices, such as the learning rate or when to stop training.

A test set is held-out data reserved for a less biased final check after those choices. All three are collections of examples, but they have different jobs.

SplitSeparate training, validation, and test collections before development choices can leak information. Related examples may need to stay together.PracticeRehearsalFinal check
  1. Use different jobsFit on practice examples. Choose settings with rehearsal examples. Reserve the final check.
Separate training, validation, and test collections before development choices can leak information. Related examples may need to stay together.

Imagine three envelopes: practice cards, rehearsal cards, and sealed quiz cards. Repeatedly opening the sealed envelope to choose changes turns it into another rehearsal envelope. Its score no longer gives the independent check we wanted.

Recognize two different failures

Generalization is a model's ability to perform usefully on new examples beyond those used to fit it. New does not mean arbitrary: a model trained on cafe orders should not be expected to predict aircraft repairs.

Overfitting happens when a model fits peculiarities of training data that do not carry over well to new cases. Imagine a wiggly line that visits every practice dot but swings wildly between them. Perfect practice results can accompany poor predictions.

Underfitting happens when the model or training fails to capture enough useful structure, even in the practice data. A constant guess for every order may miss the basic relationship between order size and preparation time.

FitIllustrative fits only: a flat guess misses the trend; a wiggly fit can chase individual examples. Held-out results decide what generalizes.Simple trend or needless wiggles?
Illustrative fits only: a flat guess misses the trend; a wiggly fit can chase individual examples. Held-out results decide what generalizes.

We compare training and held-out results, inspect mistakes, and ask whether the split resembles the intended use. Extra training is not always the answer.

Stop answers sneaking across the boundary

Data leakage occurs when information unavailable at prediction time influences model development or evaluation in a misleading way. Giving the model an order's completion time as a clue is one obvious leak.

Less obvious: put near-duplicate photographs of the same fruit in both practice and test sets. Or compute a data-cleaning setting using the whole dataset before separating the test examples. The test has helped the system prepare for itself.

For orders collected over time, a check using later orders can be more realistic than randomly mixing dates. Related examples may need to stay together. There is no single split recipe that suits every task.

LeakA test example that influences fitting or model choices contaminates an independent check. Duplicate cases and preprocessing can leak information too.PracticeFinal testKeep the boundaryAnswer information crossing back
A test example that influences fitting or model choices contaminates an independent check. Duplicate cases and preprocessing can leak information too.

Restraining the fit

Regularization is a family of techniques that discourages some kinds of overly complex fitting. One approach adds a penalty for large weights. It makes the optimizer balance matching examples against the added penalty.

Like preferring a simple recipe adjustment over a separate exception for every customer, this can encourage patterns that travel better. It is not a guarantee. Stopping when validation results stop improving, improving data coverage, or choosing a simpler model may also help.

The practice score improves while the rehearsal score worsens. Celebrate?

Pause first. It may be overfitting. Check the examples and learning curves, consider an earlier saved model, and avoid choosing the answer by repeatedly peeking at the final test set.