Exercise: How optimistic is the winning model?#
When many candidates compete on one validation set, the winner’s reported score benefits from selection. Measure that optimism while keeping a final test set untouched.
See the shared submission guidance and rubric. Run from book/exercises; the setup below supplies data, not completed answers.
# Shared simulator and small utility functions; no live service is called.
source("../R/course.R")
degrees <- 1:12
truth <- function(x) 1+2*x
set.seed(120)
make_sample <- function(n) {x <- runif(n,-1,1); data.frame(x=x,y=truth(x)+rnorm(n,0,1))}
train <- make_sample(60); validation <- make_sample(60); test <- make_sample(1000)
1. Choose once, evaluate once#
Fit all polynomial degrees on train and rank them by validation MSE. Declare a tie rule, choose one, and evaluate that fitted model on test without revising the choice. Also evaluate the prespecified degree-1 model. Plot validation and test loss by degree only after selection is frozen, labeling the test curve as a post-selection diagnostic.
# Fit candidates, freeze the chosen degree, then examine test performance.
Your explanation and evidence:
2. Repeat the selection procedure#
Repeat with 200 independently generated train/validation/test triples. For each repetition record chosen degree, winning validation MSE, selected-model test MSE, and degree-1 test MSE. Summarize selection frequencies and mean(test MSE - winning validation MSE). Do not discard repetitions in which a complex model wins.
# Store results for the entire selection procedure, not only the final winning fit.
Your explanation and evidence:
3. Write a model-selection report#
Explain why neither “degree 1 is true in this simulator” nor “degree 12 once won” justifies retrospectively changing the evaluation. Recommend how to compare more flexible candidates when data are limited, and distinguish a model’s training fit from the performance of a selection procedure.
# Produce a selection-frequency plot and an optimism summary.
Your explanation and evidence:
What to submit#
A frozen single-run comparison, repeated-selection frequencies, and an optimism estimate. Report uncertainty across repetitions rather than presenting one lucky split as decisive.