1. University MCA (AI/ML) Semester 2
  2. CAB212
  3. Unit 6

CAB212 · Unit 6: Evaluation and practice

Hyperparameter tuning and pipelines

6 practice questions

Key points

  • Hyperparameters are set before training
  • Grid = exhaustive; random = sampled
  • Pipelines prevent leakage
  • Fits = combinations x folds

Parameters are learned from data (weights, split thresholds). Hyperparameters are set before training (k in k-NN, C and gamma in SVM, tree depth, learning rate, lambda).

Search strategies, each scored by cross-validation on training data:

  • Grid search: try every combination. Number of fits = (combinations) x (folds).
  • Random search: sample combinations; often finds good values faster when only a few hyperparameters matter.
  • Bayesian optimization and successive halving: smarter, fewer trials.

Worked example: grid of 4 values of C and 3 values of gamma with 5-fold CV = 4*3*5 = 60 model fits.

A pipeline chains preprocessing (impute, scale, encode) and the model into one object. Putting preprocessing inside the pipeline means each CV fold fits it on its own training part only, which prevents leakage. Use nested CV for an unbiased estimate when tuning and evaluating on the same dataset.

Exam pitfall: the test set is used once, after tuning is finished.

Try two questions

Question 1 · Tier 3, Apply

Placing scaling inside a scikit-learn Pipeline before cross-validation helps because it:

  1. Makes the underlying model deeper
  2. Removes the need for any validation
  3. Doubles the amount of training data
  4. Fits the scaler only on each training fold, avoiding leakage
Show the answer

D. Each fold learns its own scaling statistics.

Question 2 · Tier 4, Analyse

A team tunes on the test set and picks the best model. What is the likely effect on the reported score?

  1. It is pessimistic
  2. It is exactly unbiased
  3. It is optimistically biased
  4. It becomes unrelated to the model
Show the answer

C. The test set leaked into model selection.