Scikit-Optimize, often referred to as skopt, is a simple and efficient Python library for sequential model-based optimization. It's designed to minimize expensive and noisy black-box functions, building on top of NumPy, SciPy, and Scikit-Learn. Version 0.10.2 is the current release. The library is under active development, with releases occurring periodically, making it a robust tool for tasks like hyperparameter tuning in machine learning.
pip install scikit-optimizeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `gp_minimize` to find the minimum of a noisy black-box function within a defined search space. It sets up a simple 1D objective function and then applies Gaussian Process-based Bayesian optimization. The `random_state` ensures reproducibility.
Always pin exact versions (`scikit-optimize==X.Y.Z`) in production environments and review changelogs carefully when upgrading, particularly for minor version bumps.
Pass an integer to the `random_state` parameter in all relevant functions and classes (e.g., `gp_minimize(..., random_state=42)`).
For simple, self-contained optimization, use `gp_minimize` or similar functions. For custom loops, parallel evaluations, or dynamic stopping conditions, use the `Optimizer` class with its `ask()` and `tell()` methods, understanding how to manage the state.
Ensure that your environment uses compatible versions of `numpy`, `scipy`, and `scikit-learn`. Refer to the `scikit-optimize` documentation or `setup.py` for recommended dependency versions. Using a fresh virtual environment or `conda-forge` for installation often helps manage these dependencies.
pip install scikit-optimize
from skopt.space import Real, Integer, Categorical
def objective(params):
# ...
pass
dimensions = [
Real(low=0.0, high=1.0, name='x1'),
Integer(low=1, high=10, name='x2')
]
# res = gp_minimize(objective, dimensions)def my_objective_function(params):
x = params[0]
y = params[1]
# Calculate a single scalar loss or metric
loss_value = (x - 0.5)**2 + (y + 0.2)**2
return loss_value # Must return a single scalarfrom skopt import gp_minimize from skopt.plots import plot_convergence from skopt.space import Real def objective_func(x): return x[0]**2 res = gp_minimize(objective_func, [Real(-5.0, 5.0)], n_calls=10) # Correct: Pass a list containing the OptimizeResult object plot_convergence([res]) # If comparing multiple results: # res2 = gp_minimize(objective_func, [Real(-5.0, 5.0)], n_calls=10, random_state=42) # plot_convergence([res, res2])