Pick the Penalty
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
The model with the smallest error on the validation rows is the one whose error on the test rows is reported.
Constraints
30 <= len(X) <= 60- 2 to 4 columns
alphashas 2 to 5 different values
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More scikit-learn problems
- Right Amount of BendHard
- Scored in Time OrderHard
- Spam or NotHard
- Tune Then TestHard
- Hold Some BackBeginner
- Learn Then PredictBeginner
- Names to NumbersBeginner
- Same ScaleBeginner