MST0052 · Lecture 7 · Fall 2026
90 minutes · one protocol · three families
01
Fit the model. Touched every time.
Tune and compare. Many times — never the final score.
One final, honest number.
One noisy number. The seed decides the winner.
Averages over the luck of the split.
02
Stratified by default — class ratios preserved per fold.
Plain KFold — no stratification.
Pass a splitter object for full control — shuffle=True matters when rows are ordered.
shuffle=True
Reference — screenshot this
03
The test set is touched once — the last line.
Small space — full coverage.
Large or continuous space — sample n configs.
Many configs — eliminate losers early.
Loss metrics are negated — the neg_ convention. Backup slide explains.
neg_
The pattern · memorise this
04
Pitfall 1 · The L3 rule, per fold
Scale the training set, then cross-validate — the scaler saw the validation folds.
Scaler inside the pipeline — refit on each fold's training data.
Pitfall 2 · Optimism from the best CV score
Pitfall 3 · One of 50 workflows will look great by chance
random_state
The rigorous upgrade
For coursework, GridSearchCV + a held-out test set is enough.
05
load_wine() · same splits · same metric · same rule
Step 1 · Lock the test set
Family 1 · Logistic regression
Family 2 · k-NN
k = 41 is the edge of the grid — Pitfall 3 says: extend it.
Family 3 · Random forest
One loop · one table
Test f1_macro · CV mean ± std underneath
06
Your project · all six, every family
Resampling · the k = n limit
Resampling · tighter estimates
Beyond one metric · when probabilities matter
Convention · why the score is negative
After selection · interpreting the winner
Model-agnostic, and more honest than .feature_importances_ for trees.
.feature_importances_