Syllabus Lesson 89 of 246 · Module 7: Working on new data
Module 7: Working on new data

More data for free (augmentation)

Why it matters Collecting data is expensive. Often you can make more by changing the examples you have in ways that do not change their answer.

The test digits here are written slightly off centre: shifted by up to one pixel. A model trained only on centred digits has never seen that, and scores poorly. So add shifted copies of each training digit: the label stays the same, because a 3 moved one pixel left is still a 3.

Not every change is safe

The rule for augmentation: only make changes that keep the answer the same. A mirrored digit is not real handwriting, and some flips turn one digit into something close to another. Try it and watch the score.

Augmentation: training on changed copies of your data (shifts, small rotations, crops) that keep the label true.

Words and symbols in this lesson
augmentation
changed copies of the data that keep the label true
Your turn

Write shifted_copies(imgs, labs) returning images and labels with all 9 shifts of each image (moves of -1, 0 or +1 pixels down and across, using np.roll). Then score three runs with fit_and_score: plain (training images only), shifted (your copies) and flipped (training images plus left-right mirrored copies). Set harmful to the name of the run that hurt.

Spotted a problem in this lesson? Report it · Ask about this lesson

This exercise opens soon

Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.