Machine Learning, FoundationsLesson 38 of 92

Module 4 · Generalisation, and the discipline of held-out data

Searching hyperparameters without fooling yourself

In this lesson

  • 9 min read
  • 6 reading sections
  • Knowledge check
  • Lesson 7 of 10 in this chapter

This chapter’s goalDesign a validation scheme that matches the structure of the data (grouped, stratified or time-ordered as required) run a hyperparameter search inside it without contaminating the estimate, and state from a learning curve whether the next improvement should come from more data, better features or a different model.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmWatch1:49Not available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 8Free · no account needed
Lesson steps

Parameters and hyperparameters

Parameters are learned from the data: the coefficients, the split thresholds, the network weights. Hyperparameters are set by you before training: max_depth, alpha, learning_rate, n_estimators.

The distinction matters because parameters are fitted on the training set and hyperparameters must be chosen on the validation set. Choosing them on the training set means picking whatever fits it hardest, which is always the most complex option available.

Grid search, and why it wastes most of its budget

Python
from sklearn.model_selection import GridSearchCV
grid = {"model__max_depth": [3, 5, 7],
        "model__learning_rate": [0.01, 0.05, 0.1],
        "model__min_samples_leaf": [10, 20, 50]}
search = GridSearchCV(pipe, grid, cv=5, scoring="roc_auc", n_jobs=-1)

Every combination: 3 x 3 x 3 = 27 configurations, times 5 folds, is 135 fits. Adding one more value to one parameter takes it to 180.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the How a Language Model Actually Works exam.

Stuck on something?Ask Funke, your AI tutor

How to cite: Addaly (2026) ‘Searching hyperparameters without fooling yourself’, in Machine Learning, Foundations. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/machine-learning-foundations/hyperparameter-search (Accessed: 29 November 2026).