{"id":5052,"library":"scikit-optimize","title":"scikit-optimize (skopt)","description":"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.","status":"active","version":"0.10.2","language":"en","source_language":"en","source_url":"https://github.com/scikit-optimize/scikit-optimize","tags":["bayesian optimization","hyperparameter tuning","machine learning","optimization","scikit-learn"],"install":[{"cmd":"pip install scikit-optimize","lang":"bash","label":"Basic Installation"},{"cmd":"pip install scikit-optimize[plots]","lang":"bash","label":"Installation with Plotting Dependencies"},{"cmd":"conda install conda-forge::scikit-optimize","lang":"bash","label":"Conda Installation"}],"dependencies":[{"reason":"Core dependency for numerical operations.","package":"numpy","optional":false},{"reason":"Core dependency for scientific computing.","package":"scipy","optional":false},{"reason":"Core dependency, often used for hyperparameter tuning tasks.","package":"scikit-learn","optional":false},{"reason":"Optional dependency for plotting optimization results.","package":"matplotlib","optional":true}],"imports":[{"symbol":"gp_minimize","correct":"from skopt import gp_minimize"},{"symbol":"forest_minimize","correct":"from skopt import forest_minimize"},{"note":"While 'skopt.optimizer' exists, the top-level import 'from skopt import Optimizer' is the commonly documented and simpler approach for direct use.","wrong":"from skopt.optimizer import Optimizer","symbol":"Optimizer","correct":"from skopt import Optimizer"},{"note":"BayesSearchCV is exposed directly at the top level of the skopt package for convenience, despite residing within a submodule.","wrong":"from skopt.searchcv import BayesSearchCV","symbol":"BayesSearchCV","correct":"from skopt import BayesSearchCV"}],"quickstart":{"code":"import numpy as np\nfrom skopt import gp_minimize\n\ndef f(x):\n    # An example objective function to minimize\n    # In a real scenario, this could be a machine learning model training and evaluation\n    return (np.sin(5 * x[0]) * (1 - np.tanh(x[0] ** 2)) * \n            np.random.randn() * 0.1 + (x[0] - 0.5)**2)\n\n# Define the search space: a single dimension from -2.0 to 2.0\nspace = [(-2.0, 2.0)]\n\n# Perform Bayesian optimization using Gaussian Processes\n# n_calls: total number of objective evaluations\n# n_random_starts: number of random points to sample before fitting the surrogate model\n# random_state: for reproducibility\nres = gp_minimize(f, space, n_calls=20, n_random_starts=5, random_state=123)\n\nprint(f\"Optimal value found: x*={res.x[0]:.4f}, f(x*)={res.fun:.4f}\")","lang":"python","description":"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."},"warnings":[{"fix":"Always pin exact versions (`scikit-optimize==X.Y.Z`) in production environments and review changelogs carefully when upgrading, particularly for minor version bumps.","message":"Despite being actively developed, `scikit-optimize` has previously been described as 'experimental and under heavy development'. This can imply that API stability, especially between minor versions, might not be as rigid as more mature libraries, potentially leading to breaking changes.","severity":"gotcha","affected_versions":"<=0.10.1"},{"fix":"Pass an integer to the `random_state` parameter in all relevant functions and classes (e.g., `gp_minimize(..., random_state=42)`).","message":"Reproducibility of optimization runs depends on setting the `random_state` parameter consistently across all components that use randomness (e.g., `gp_minimize`, `Optimizer`, base estimators in `BayesSearchCV`). Failing to do so can lead to different results across runs.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"The library offers two main interfaces: direct minimization functions (e.g., `gp_minimize`) for complete optimization loops, and the `Optimizer` class for an 'ask-and-tell' interface, providing more fine-grained control over the optimization process. Confusing these or misapplying the `ask-and-tell` pattern can lead to incorrect or inefficient optimization loops.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"As `scikit-optimize` is built on top of NumPy, SciPy, and Scikit-learn, version incompatibilities with these underlying libraries can occur. Outdated or incompatible versions of these dependencies might cause installation issues, runtime errors, or unexpected behavior.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}