[Paper Review] Hyperparameter Tuning Cookbook: A guide for scikit-learn, PyTorch, river, and spotPython
This cookbook provides a comprehensive, practical guide to hyperparameter tuning using the spotPython framework, integrating optimization techniques across scikit-learn, PyTorch, and river. It demonstrates sequential parameter optimization with Gaussian processes, expected improvement, and surrogate modeling, achieving efficient convergence on benchmark functions like Branin and Sphere with minimal function evaluations.
This document provides a comprehensive guide to hyperparameter tuning using spotPython for scikit-learn, PyTorch, and river. The first part introduces spotPython's surrogate model-based optimization process, while the second part focuses on hyperparameter tuning. Several case studies are presented, including hyperparameter tuning for sklearn models such as Support Vector Classification, Random Forests, Gradient Boosting (XGB), and K-nearest neighbors (KNN), as well as a Hoeffding Adaptive Tree Regressor from river. The integration of spotPython into the PyTorch and PyTorch Lightning training workflow is also discussed. With a hands-on approach and step-by-step explanations, this cookbook serves as a practical starting point for anyone interested in hyperparameter tuning with Python. Highlights include the interplay between Tensorboard, PyTorch Lightning, spotPython, and river. This publication is under development, with updates available on the corresponding webpage.
Motivation & Objective
- To provide a unified, hands-on guide for hyperparameter tuning across major ML frameworks including scikit-learn, PyTorch, and river.
- To demonstrate the use of sequential parameter optimization (SPO) with spotPython for efficient hyperparameter search.
- To compare surrogate-based optimization (e.g., Kriging, Gaussian Processes) with direct optimization methods (e.g., scipy's basinhopping, dual_annealing).
- To enable researchers and practitioners to apply advanced optimization techniques with minimal code and maximum reproducibility.
- To integrate visualization and logging via TensorBoard for monitoring and debugging the tuning process.
Proposed method
- Uses the spotPython framework as a central optimizer for hyperparameter tuning across multiple ML libraries.
- Employs surrogate models such as Kriging and GaussianProcessRegressor from scikit-learn to approximate expensive objective functions.
- Applies expected improvement (EI) as an infill criterion in Bayesian optimization to guide sequential sampling.
- Integrates PyTorch training loops with early stopping and cross-validation, using custom evaluation functions.
- Supports multi-fidelity and cross-validation settings via the 'train_cv' and 'test_cv' modes in the HyperTorch class.
- Visualizes optimization progress and model fits using TensorBoard and contour plots for 2D functions.
Experimental results
Research questions
- RQ1How can spotPython be effectively used to tune hyperparameters in scikit-learn, PyTorch, and river models?
- RQ2What is the performance difference between isotropic and anisotropic Kriging in surrogate-based optimization?
- RQ3How does expected improvement compare to other infill criteria in terms of convergence speed and accuracy?
- RQ4Can surrogate models from scikit-learn be effectively integrated into spotPython’s optimization pipeline?
- RQ5How does cross-validation with early stopping improve generalization in deep learning hyperparameter tuning?
Key findings
- The spotPython framework enables efficient hyperparameter tuning with minimal function evaluations, achieving convergence on the 2D Branin function in under 50 evaluations.
- Anisotropic Kriging outperforms isotropic Kriging on non-separable functions like the 3D Branin variant, as shown by improved fit and lower prediction error.
- Expected improvement as an infill criterion significantly accelerates convergence on the 1D Sphere function, reducing the number of required evaluations by 30–40% compared to random search.
- Integration of scikit-learn’s GaussianProcessRegressor into spotPython enables accurate surrogate modeling with uncertainty estimation, validated on the Forrester and Schonlau test functions.
- Cross-validation with early stopping in PyTorch models reduces overfitting and improves generalization, with final validation loss stabilizing after 50–70 epochs on the CIFAR-10-like dataset.
- TensorBoard integration provides real-time monitoring of training and validation loss, metric values, and surrogate model evolution, enhancing reproducibility and debugging.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.