← Back to blog
TechnicalSeptember 29, 2026·7 min read

Hyperparameter Search Without Burning a Month of Compute

Grid Search, Random Search, and Bayesian Optimization compared through compute cost, repeated validation, and threshold selection.

Hyperparameter Search Without Burning a Month of Compute

Imagine searching for a good cookie recipe. Grid search bakes every combination on a chosen list of ingredient settings. Random search samples combinations from a defined range. Bayesian optimization uses the results of earlier batches to guide what it tries next. Exhaustive search covers its chosen grid, not every possible recipe, and random search follows a sampling distribution rather than instinct.

These approaches offer different ways to tune a machine learning model. I compared them on an XGBoost classifier using the Breast Cancer Wisconsin dataset. Their initial ROC-AUC scores were close, but their search times and the variation across validation folds told a fuller story. A single cross-validation estimate depends on how the data was split; a difference of a few ten-thousandths may reflect that variation rather than a dependable advantage.

The setup

The dataset contains 569 records and 30 features. A stratified 80/20 split assigned 455 records to training and 114 to a held-out test set. The searches used five-fold stratified cross-validation on the training portion, tuning tree count, depth, learning rate, row subsampling, and column subsampling. The strategies used different search budgets, so this is a comparison of these particular configurations and budgets.

Experiment design separating 455 training records from a 114-record held-out test set.
Figure 1. The training partition guides tuning; the held-out partition checks the final classifications.

Grid Search evaluated all 243 points in its grid and took about 209 seconds. Random Search evaluated 20 sampled configurations in about 16 seconds. Bayesian Optimization used Optuna's Tree-structured Parzen Estimator (TPE) for 40 trials, of which 32 completed and eight were pruned, in about 25 seconds. These are measured times for this experiment, not general runtime guarantees.

Pruning: don't finish trials that are already losing

Optuna's median pruner compares a trial's best intermediate result with the median at the same step among previous completed trials. In this experiment, intermediate scores came from cross-validation folds, and eight of the 40 trials were stopped early. Pruning can save computation, but it can also discard a trial that would improve later and can change the eventual search result. The objective must report intermediate values and call trial.should_prune(); configuring a pruner alone does not stop trials.

study = optuna.create_study(
    direction="maximize",
    pruner=optuna.pruners.MedianPruner(
        n_startup_trials=5, n_warmup_steps=2
    ),
)

Are they actually the same?

The best scores in the initial cross-validation search were approximately 0.9951 for Grid Search, 0.9946 for Random Search, and 0.9951 for Bayesian Optimization. These are validation scores, not held-out test ROC-AUC values. The close estimates suggest similar performance in this run, but they do not establish equivalence between the search methods.

Cross-validation ROC-AUC and search time for Grid Search, Random Search and Bayesian Optimization.
Figure 2. Initial validation scores versus search time. Bubble size encodes evaluation count.

Making the comparison earn its conclusion

Each selected configuration was also re-scored with five-fold stratified cross-validation repeated three times, giving 15 paired fold scores. Pairwise Wilcoxon signed-rank tests were used to explore the differences. Pairing keeps the comparisons on matching splits, but repeated-CV folds share training observations and are dependent. The resulting p-values should therefore be treated as exploratory rather than definitive evidence.

The repeated-CV mean ROC-AUC values were 0.9943 (SD 0.0052) for Grid Search, 0.9932 (SD 0.0065) for Random Search, and 0.9933 (SD 0.0063) for Bayesian Optimization. The experiment reported these unadjusted pairwise test results:

ComparisonWilcoxon WUnadjusted p
Grid vs. Random10.50.045
Grid vs. Bayesian29.50.149
Random vs. Bayesian3.00.861
Distribution of the 15 repeated cross-validation scores for each selected configuration.
Figure 3. Repeated-CV fold scores. The annotations show unadjusted p-values; the folds are dependent and the comparisons are exploratory.

Grid versus Random has a nominal p-value of 0.045. With three pairwise comparisons, it does not pass a simple Bonferroni threshold of 0.05/3, approximately 0.0167. The overlapping folds are a further reason for caution. The larger p-values for the other pairs do not prove that the methods are equivalent. The supported observation is narrower: their mean scores were close, while Bayesian Optimization used about one-eighth of the Grid Search time in this run. Random Search was faster still.

These rescored configurations also do not measure the variability of repeating the entire search. For a stronger comparison of tuning procedures, the complete search belongs inside each training partition of a nested evaluation.

The part that is easy to skip: choosing the decision threshold

A probabilistic binary classifier commonly uses a 0.5 decision cutoff, but that threshold need not match the desired balance of errors. Out-of-fold predictions on the training data, keeping the test set separate, selected an F1-maximizing threshold of 0.61. Choosing a decision threshold is distinct from calibrating predicted probabilities.

Precision, recall and F1 over decision thresholds, using out-of-fold training predictions.
Figure 4. Choosing a decision threshold from out-of-fold training predictions. This is separate from probability calibration.

On the held-out test set, moving the threshold from 0.50 to 0.61 kept precision at 1.00 but reduced recall from 0.929 to 0.905 and F1 from 0.963 to 0.950. A threshold that maximizes training-fold F1 does not automatically generalize. In this example, the higher threshold missed an additional malignant case.

At the default threshold, the confusion matrix contains 72 correctly classified benign cases, 39 correctly classified malignant cases, and three malignant cases classified as benign. Those counts give 111/114 correct predictions, about 97.4% accuracy. The overall percentage hides which errors occurred. This small benchmark experiment illustrates that distinction; it does not establish clinical performance.

Held-out confusion matrix: 72 benign and 39 malignant cases classified correctly, three malignant cases missed.
Figure 5. Held-out classifications for the Bayesian-optimized model at the default threshold.

So, what's actually driving the score?

Optuna's functional ANOVA analysis estimated similar relative importance for max_depth (0.23), colsample_bytree (0.23), and learning_rate (0.23), followed by subsample (0.19) and n_estimators (0.13). The rounded values describe variation within this experiment's evaluated search space. They are not a universal ranking and do not, by themselves, establish why one search strategy was faster.

Relative hyperparameter importance estimated by functional ANOVA.
Figure 6. Relative hyperparameter importance within the evaluated search space.

What this doesn't claim

Every result here comes from one 569-record dataset and one set of search budgets. Fold-score differences are small, the repeated folds are dependent, and three unadjusted comparisons were made. The 114-record test results are point estimates without confidence intervals. Search-space discretization, random seeds, hardware, and whether the complete tuning procedure is repeated can all affect the comparison.

What to take

In this experiment, Bayesian Optimization found a configuration with a validation score close to Grid Search while spending about 25 seconds instead of 209 seconds on the search. That is an encouraging compute tradeoff, not proof that Bayesian Optimization is universally superior or statistically equivalent to Grid Search. Random Search remains a useful, inexpensive baseline. Repeated validation, honest uncertainty, and a separate final test help prevent small score differences from becoming oversized conclusions. The confusion matrix and threshold check add information that ROC-AUC alone cannot provide.

References

  1. Akiba, T., Sano, S., Yanase, T., Ohta, T., & Koyama, M. (2019). Optuna: A next-generation hyperparameter optimization framework. Proceedings of the 25th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining. DOI: 10.1145/3292500.3330701 Read source
  2. Bergstra, J., & Bengio, Y. (2012). Random search for hyper-parameter optimization. Journal of Machine Learning Research, 13, 281-305. jmlr.org/papers/v13/bergstra12a.html Read source
  3. Bergstra, J., Bardenet, R., Bengio, Y., & Kégl, B. (2011). Algorithms for hyper-parameter optimization. Advances in Neural Information Processing Systems, 24. proceedings.neurips.cc/paper/2011 (hash 86e8f7ab) Read source
  4. Li, L., Jamieson, K., DeSalvo, G., Rostamizadeh, A., & Talwalkar, A. (2018). Hyperband: A novel bandit-based approach to hyperparameter optimization. Journal of Machine Learning Research, 18(185), 1-52. jmlr.org/papers/v18/16-558.html Read source
  5. Snoek, J., Larochelle, H., & Adams, R. P. (2012). Practical Bayesian optimization of machine learning algorithms. Advances in Neural Information Processing Systems, 25. proceedings.neurips.cc/paper/2012 (hash 05311655) Read source
  6. SciPy. Wilcoxon signed-rank test. Read source
  7. Scikit-learn. Statistical comparison of models using grid search. Read source
  8. Scikit-learn. Nested versus non-nested cross-validation. Read source

Want to share your own experience? Every member can write here: reach out and we'll help you publish your first post.