explaingit

bayesian-optimization/bayesianoptimization

8,627PythonAudience · dataComplexity · 2/5Setup · easy

TLDR

A Python library for finding the best input settings for a slow or expensive function without brute-force search. It uses Bayesian optimization with a Gaussian process model to intelligently decide where to test next, minimizing the number of runs needed.

Mindmap

mindmap
  root((repo))
    What it does
      Finds best parameters
      Minimizes function calls
    How it works
      Gaussian process model
      Explore vs exploit
      Domain reduction
    Usage
      Define target function
      Set parameter bounds
      Call maximize
    Install
      pip install
      Conda install
    Use cases
      ML hyperparameters
      Scientific experiments
      Pipeline tuning
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Tune hyperparameters for a machine learning model, like learning rate and layer count, efficiently without trying every combination

USE CASE 2

Find the optimal settings for a chemistry experiment or simulation where each run takes hours to complete

USE CASE 3

Narrow down the best configuration for a slow API or data pipeline step without running a full grid search

Tech stack

Pythonscikit-learnNumPy

Getting it running

Difficulty · easy Time to first run · 30min

In plain English

This is a Python library for finding the best settings for a function when running that function is slow or expensive. The problem it solves is common in machine learning and scientific computing: you have a process that takes some input parameters and produces a score, but running it even once takes significant time or resources. You want to find the combination of inputs that produces the best score without having to try thousands of combinations at random. The technique it uses is called Bayesian optimization. The basic idea is that after each test, the algorithm builds a statistical model of how the function behaves across the input space. That model, called a Gaussian process, gives the algorithm two things: an estimate of what the output will be at any untested point, and a measure of how uncertain that estimate is. The algorithm then uses this information to decide where to look next, balancing between exploring areas it knows little about and focusing on areas that look promising. Using the library is straightforward. You define a Python function that takes named parameters and returns a number you want to maximize. You tell the optimizer the allowed range for each parameter. Then you call the maximize method and specify how many random starting points to try and how many Bayesian-guided steps to run afterward. After it finishes, you can read off the best parameter combination it found. The library supports constrained optimization, meaning you can set hard limits on what parameter values are allowed. It also includes a feature called SequentialDomainReduction, which progressively narrows the search region as the optimizer gains confidence, helping it converge faster on problems where the optimum is in a small corner of the parameter space. The library is installable via pip or Conda and is written in pure Python. It is actively developed and citable in academic work, with BibTeX citations provided for the core method and its extensions.

Copy-paste prompts

Prompt 1
Using the bayesian-optimization Python library, write a script that finds the best learning rate and batch size for a PyTorch model in at most 30 evaluations
Prompt 2
Show me how to set up bayesian-optimization to maximize a black-box function with 3 parameters, plot the progress, and print the best result found
Prompt 3
How do I use SequentialDomainReduction in bayesian-optimization to speed up convergence when the optimum is likely in a small region of the parameter space?
Prompt 4
Write a Python example using bayesian-optimization to tune the C and gamma parameters of an SVM and print the best cross-validation score it found
Open on GitHub → Explain another repo

← bayesian-optimization on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.