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-optimizationVerified import paths — ran on the pinned version, not inferred.
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.
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)`.
Ensure that every parameter in your objective function has a corresponding `(lower_bound, upper_bound)` tuple defined in the `pbounds` dictionary passed to `BayesianOptimization`.
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.
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).
Ensure the package is installed with `pip install bayesian-optimization` and import it using `from bayes_opt import BayesianOptimization`.
Install the library using pip: `pip install bayesian-optimization`.
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']`.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`.
Downgrade the `scipy` package to a compatible version, for example, `pip install scipy==1.7.2`.
No dependency data recorded yet.