Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

Bayesian Optimization

Bayesian optimization uses past evaluations and probabilistic models to find high-performing settings for costly ML workloads with limited compute.

Bayesian optimization is a method for finding high-performing settings of an expensive-to-evaluate function by learning from previous evaluations. It builds a probabilistic model of how inputs affect results, then uses that model to choose the next experiment. In machine learning, this makes it useful for finding strong training configurations within a limited computational budget.

Its foundations include Harold Kushner's 1964 sequential search method and Jonas Mockus's 1975 Bayesian extremum-seeking formulation. Today, it is a central technique in hyperparameter tuning and automated machine learning.

How Bayesian Optimization Works#

The objective function measures the quality of a candidate configuration. For model training, an evaluation involves training with selected hyperparameters and measuring performance on validation data. Tunable inputs include learning rate, batch size, and regularization strength.

A surrogate model is a computationally cheaper approximation of the objective. A common choice is a Gaussian process: a probability distribution over possible functions that predicts both an outcome and its uncertainty. Bayesian updating combines prior assumptions with observed evaluations to produce a posterior distribution. An acquisition function uses this distribution to select another candidate; its measured result feeds back into the surrogate until the evaluation budget is exhausted.

This is a machine-learning-based optimization approach: the surrogate learns from configuration–result pairs. Its uncertainty quantification helps determine which additional measurements are valuable.

Acquisition Functions and Exploration#

Candidate selection balances exploitation, which favors settings predicted to perform well, with exploration, which investigates uncertain regions. Common acquisition functions express this balance differently:

  • Expected Improvement (EI): Scores the expected amount by which a candidate improves on a reference result.
  • Probability of Improvement (PI): Scores the probability of exceeding a reference result by a specified margin.
  • Upper Confidence Bound (UCB): For maximization, combines the predicted mean with an uncertainty bonus, giving uncertain candidates additional priority.

These acquisition strategies are inexpensive to evaluate compared with training a model or running a physical experiment. Their optimization directs the next expensive evaluation.

Applications in Machine Learning and Computer Vision#

Bayesian optimization is especially useful when individual evaluations consume substantial time and the search contains a manageable number of influential variables. Established applications include engineering design, materials experiments, and reinforcement learning controller tuning.

In computer vision, it selects training settings for convolutional neural networks. Jasper Snoek, Hugo Larochelle, and Ryan P. Adams demonstrated this application in their 2012 practical Bayesian optimization algorithm, alongside tuning structured support vector machines and topic models.

Ultralytics YOLO exposes Bayesian search through its Ray Tune integration: setting use_ray=True and search_alg="bayesopt" selects Bayesian optimization for training hyperparameters. For YOLO26 object detection, the search maximizes the task's default mean average precision metric.

Grid search evaluates a predefined collection of combinations, while random search samples configurations independently. Bayesian optimization uses previous outcomes to guide subsequent choices. Gradient descent updates parameters using derivatives; Bayesian optimization handles expensive black-box objectives through evaluations and a surrogate.

Optuna's sampling algorithms include Gaussian-process Bayesian optimization, random sampling, and the Tree-structured Parzen Estimator (TPE). TPE models parameter distributions associated with better and worse outcomes, then favors candidates with a larger ratio between those densities. Optuna is the optimization framework; the selected sampler determines its search strategy.

A Python Example#

Install bayesian-optimization with pip install bayesian-optimization. This uses the objective and bounds from the package's introductory optimization example:

from bayes_opt import BayesianOptimization


def objective(x, y):
    """Return the objective value to maximize."""
    return -(x**2) - (y - 1) ** 2 + 1


optimizer = BayesianOptimization(
    f=objective,
    pbounds={"x": (2, 4), "y": (-3, 3)},
    random_state=1,
    verbose=0,
)
optimizer.maximize(init_points=2, n_iter=15)
best = optimizer.max
print(f"Best objective: {best['target']:.4f}")

The output reports the best measured objective after two random evaluations and fifteen acquisition-guided evaluations. Within these bounds, the exact maximum is -3 at x=2, y=1.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning