Registry / ai-ml / bayesian-optimization

bayesian-optimization

JSON →
library3.3.0pypypi✓ verified 22d ago

The bayesian-optimization library provides a Python implementation of the Bayesian Optimization (BO) algorithm, specifically designed for constrained global optimization of expensive black-box functions. It leverages Bayesian inference and Gaussian processes to efficiently find the maximum value of an unknown function with minimal evaluations. The current version is 3.2.1, and the project is actively maintained with a regular release cadence, requiring Python >=3.9.

pip install bayesian-optimization
INSTALL
IMPORT
SIG · BAYESIAN-OPTIMIZAT
B
bayesian-optimization
ai-mlpythonv3.3.0
Install
9.9s avg
Import
3086ms
Disk
281MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 9.9s · import 3.086s · 271MB
281MB installed
● package 281MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BayesianOptimization
from bayes_opt import BayesianOptimization

This example demonstrates how to set up and run a basic Bayesian Optimization to maximize a simple two-dimensional black-box function. It defines the objective function, specifies the search space bounds, initializes the optimizer, and then runs the maximization process for a set number of iterations.

from bayes_opt import BayesianOptimization import os def black_box_function(x, y): """Function with unknown internals we wish to maximize. This is just serving as an example, for all intents and purposes think of the internals of this function, i.e.: the process which generates its output values, as unknown. """ # Example: A simple 2D quadratic function return -x ** 2 - (y - 1) ** 2 + 1 # Bounded region of parameter space pbounds = {'x': (0, 2), 'y': (0, 3)} optimizer = BayesianOptimization( f=black_box_function, pbounds=pbounds, random_state=1, ) # Perform 2 initial random points and 5 iterations of Bayesian Optimization optimizer.maximize( init_points=2, n_iter=5, ) print(f"Best parameters found: {optimizer.max['params']}") print(f"Maximum value found: {optimizer.max['target']}")
null --version
Debug
Known issues
gotchaThe `BayesianOptimization` class is designed to find the *maximum* of the objective function by default. If your goal is to *minimize* a function `f(x)`, you should define your objective function to return `-f(x)`.
fix
Modify your objective function to return the negative of the value you wish to minimize. For example, `def objective_to_minimize(x): return -my_function(x)`.
affects: All versions
gotchaThis is a constrained optimization technique, meaning you must provide explicit upper and lower bounds for all parameters in the search space (`pbounds`). Failing to define bounds for any parameter will result in an error or incorrect behavior.
fix
Ensure that every parameter in your objective function has a corresponding `(lower_bound, upper_bound)` tuple defined in the `pbounds` dictionary passed to `BayesianOptimization`.
affects: All versions
gotchaBayesian Optimization is most effective for computationally *expensive* black-box functions where each evaluation takes a significant amount of time (minutes or hours). Using it for very cheap, quickly computable functions may be less efficient than simpler optimization methods like grid search or random search due to the overhead of fitting the surrogate model.
fix
Consider the computational cost of your objective function. If evaluations are very fast, simpler optimization strategies might be more appropriate or faster. Bayesian Optimization shines when minimizing the number of evaluations is critical.
affects: All versions
gotchaStandard Bayesian Optimization techniques, particularly those relying on Gaussian Processes, can struggle with high-dimensional search spaces. Performance tends to degrade significantly for problems with more than approximately 20 dimensions due to the 'curse of dimensionality' affecting the surrogate model.
fix
For higher-dimensional problems, consider dimensionality reduction techniques, feature selection, or specialized Bayesian Optimization variants designed for high-dimensional spaces (e.g., those using random embeddings or sparse structures).
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'bayesian-optimization'
The Python import statement uses the package name ('bayesian-optimization') instead of the module name ('bayes_opt'), or the package is not installed.
fix
Ensure the package is installed with `pip install bayesian-optimization` and import it using `from bayes_opt import BayesianOptimization`.
ModuleNotFoundError: No module named 'bayes_opt'
The `bayesian-optimization` library is not installed in the current Python environment.
fix
Install the library using pip: `pip install bayesian-optimization`.
AttributeError: 'BayesianOptimization' object has no attribute 'max'
The `.max` attribute for directly accessing the best optimization results (target and parameters) was deprecated or removed in recent versions of the library.
fix
Access the best results through `optimizer.res['max']`, which is a dictionary containing `{'target': ..., 'params': ...}`. For example, `optimizer.res['max']['target']` and `optimizer.res['max']['params']`.
ImportError: cannot import name 'UtilityFunction' from 'bayes_opt'
The `UtilityFunction` class was renamed to `AcquisitionFunction` in version 2.0.0 and later of the `bayesian-optimization` library, causing an import error for code written with older versions.
fix
Update the import statement to `from bayes_opt.util import AcquisitionFunction` or downgrade the library to a compatible version, e.g., `pip install bayesian-optimization==1.5.1`.
TypeError: 'float' object is not subscriptable
This error often occurs due to incompatibility between the `bayesian-optimization` library and newer versions of `scipy`.
fix
Downgrade the `scipy` package to a compatible version, for example, `pip install scipy==1.7.2`.
Upgrade
Version history
3.3.0latest on PyPI · released May 30, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
25 hits · last 30 days
node
20
OpenAI (training)
2
Resources
bayesian-optimization — pip install bayesian-optimization · libregistry