/W13
实验Lab: Tune and regularise
- Dataset
- UCI Wine Quality (6,497 rows, CC BY 4.0)
- Time
- 3 hours
This week you'll be able to
- Run grid, random, and Bayesian (Optuna) searches on the same budget and compare them.
- Read a learning curve and say whether a model needs more or less capacity.
- Fit Ridge, Lasso, and Elastic Net, choose alpha by CV, and explain why Lasso zeroes weights.
Goal
Compare grid, random, and Bayesian search on a fixed budget. Then use regularisation to tame a model that overfits, and read the learning curves.
Data
Physicochemical tests on Portuguese red and white wines, with a quality score from 3 to 9.
import pandas as pd
wine = pd.read_csv("https://archive.ics.uci.edu/static/public/186/data.csv")
wine["is_red"] = (wine["color"] == "red").astype(int)
X = wine.drop(columns=["quality", "color"])
y = wine["quality"]Tasks
- Treat quality as a number and fit gradient boosting with default settings. Record CV RMSE. This is the baseline.
- Define a search space for four hyperparameters (Procedure 17.1). Use log scales where they belong.
- Run grid search, random search, and an Optuna study, each with 40 trials (Procedures 17.2 to 17.4). Record the best CV score and the wall time for each.
- Plot best-score-so-far against trial number for all three. When does each one reach within 1% of its final score?
- Score the winner once on a held-out test set. Compare with its CV score. Explain the gap.
- Expand the features with degree-3 polynomials and fit plain linear regression. Compare train and test RMSE.
- Fit Ridge, Lasso, and Elastic Net with alpha chosen by CV (Procedures 18.1 to 18.3). How many coefficients does Lasso set to zero?
- Plot learning curves for the unregularised and best regularised models (Procedure 18.5). Diagnose each one: high bias, high variance, or a good fit?
Deliverable
A notebook with the search comparison table, the best-so-far plot, the regularisation table, and both learning curves, each with its diagnosis.
Done when
- All three searches use the same budget and the same folds.
- The test set is used once, after tuning.
- Each learning curve has a one-line diagnosis.
Stretch
Treat quality as a class and use regularised logistic regression (Procedure 18.4). Is quality better framed as regression or classification? Argue from the error costs.