Skip to content

Overfit on Purpose

You'll train a model that memorizes its training data, watch the held-out score fall as the training score climbs, and then rein it in.

About

A model with enough freedom will learn the noise in your training data along with the signal, and it will look perfect on the rows it has seen and useless on the rows it hasn't. You can't really understand regularization until you've watched that happen on a chart you made. Use any small dataset, a model with a knob that controls how much it can memorize (tree depth, polynomial degree, or the number of neighbors), and a held-out set. What counts is a validation curve with both lines on it, cross-validation to make the numbers trustworthy, and a final setting you chose from the curve rather than from a tutorial.

At a glance

Per requirement
25 XP
Completion bonus
150 XP
Requirements
5
Takes
One weekend
Skill level
Intermediate (months of practice)
Cost
Free
Supplies
Nothing special
Where
At home
Other people
On your own
Locked for now
Earn two more Common badges in Machine Learning to open this one. Log in to see how far along you are.

Requirements

  1. 1
    Fit a polynomial to 30 noisy points at degrees 1, 3, 9 and 15. Make the points yourself: a sine wave plus random noise is the classic. Plot all four fits over the points on one chart. Degree 15 will thread through every point and whip wildly between them. Take a screenshot of the four curves. Photo
  2. 2
    Plot training error and held-out error against degree on one chart. Make 30 more points from the same wave for the held-out set. Training error falls forever; held-out error falls, bottoms out and climbs. The degree at the bottom of the second curve is the one you want, and it's usually lower than you'd guess. Take a screenshot of the chart with the bottom marked. Photo
  3. 3
    Do the same with a decision tree on a real dataset, sweeping the depth. Depths 1 through 20 on any public classification set. Plot training and validation accuracy against depth. A tree with no depth limit scores 100 percent on training rows and is almost always worse on validation than a depth of 4 to 8. Take a screenshot of the curve. Photo
  4. 4
    Replace the single split with 5-fold cross-validation and show the spread. Split the training rows into five parts, train on four and score on the fifth, five times over, and report the mean and standard deviation at each depth. If the standard deviation is bigger than the gap between two depths, you can't tell them apart, and that's worth knowing before you claim one is better. Take a screenshot of the mean and spread per depth. Photo
  5. 5
    Add a regularization knob and find where it helps. For the tree, try a minimum number of rows per leaf. For a linear model, try ridge or lasso at a few strengths. Show the validation score with and without, and name the setting you'd ship. Then write three sentences on what the curve told you that a single accuracy number couldn't. Post the scores with the sentences. Photo