FunctionRacerProblemsRace

Pick the Penalty

Hardscikit-learnPython

Three sets of rows keep a model honest: one to fit, one to choose settings, one to report.

1. Split X and y into a part to keep and a test part with test_size=0.25 and random_state=0.
2. Split the kept part again into training and validation parts with test_size=0.25 and random_state=1.
3. For each alpha in alphas, fit a ridge regression on the training part and measure its mean squared error on the validation part.
4. Return the mean squared error on the test part of the model whose validation error was lowest (the first such alpha on a tie).

Example 1

X [[0,0],[1,3],[2,1],[3,4],[4,2],[5,0],[6,3],[0,1],[1,4],[2,2],[3,0],[4,3],[5,1],[6,4],[0,2],[1,0],[2,3],[3,1],[4,4],[5,2],[6,0],[0,3],[1,1],[2,4],[3,2],[4,0],[5,3],[6,1],[0,4],[1,2]]
y [0,0,5,2,7,12,9,0,0,2,7,7,9,9,0,2,2,7,4,9,14,-3,2,2,4,9,9,11,-3,2]
alphas [0.1,10.0,1000.0]
returns 0.7299499108366546

The model with the smallest error on the validation rows is the one whose error on the test rows is reported.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More scikit-learn problems