By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Hyperparameter tuning is the systematic search for the best settings that control a learning algorithm (e.g., tree depth, learning rate, regularization strength). These knobs are not learned from the data; they must be chosen before training. Picking good values can shrink error dramatically, turning a mediocre model into a production‑ready one. Real‑world example: A telecom company builds a churn‑prediction model with XGBoost. The default max‑depth = 6 and learning‑rate = 0.3 give 78 % AUC, but after a focused search the optimal depth = 4 and η = 0.07 push AUC to 84 %—enough to justify a targeted retention campaign.
n_estimators
C
kernel
patience
logspace(-4, 0, 10)
alpha
roc_auc
neg_log_loss
X_train, X_test, y_train, y_test = train_test_split(...)
python param_grid = { "max_depth": [3, 5, 7], "learning_rate": np.logspace(-3, -1, 5), "n_estimators": [100, 300, 500] }
GridSearchCV
RandomizedSearchCV
skopt.BayesSearchCV
optuna.create_study()
X_train, y_train
scoring
logspace(-4, 4)
n_jobs=-1
max_iter
average_precision
Scenario: Your XGBoost model’s validation loss plateaus after 150 trees, but you set n_estimators=500. Answer: Use early stopping (early_stopping_rounds=30) to stop training automatically. Why: Saves time and prevents over‑fitting by halting when no improvement is seen.
n_estimators=500
early_stopping_rounds=30
Scenario: You have three hyperparameters to tune, each with 5 possible values. Grid Search would evaluate 125 models. You only have time for ~30 fits. Answer: Choose Random Search with n_iter=30. Why: Random sampling covers the space more efficiently than a truncated grid.
n_iter=30
Scenario: After tuning, the test AUC is significantly lower than the CV AUC. Answer: You likely performed data leakage (e.g., used test data in CV). Why: Leakage inflates CV scores; the true performance appears only on the untouched test set.
scoring='neg_log_loss'
model.fit(..., eval_set=[(X_val, y_val)], early_stopping_rounds=20)
np.logspace
E[max(0, f_best - f(x))]
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.