Optuna searches for useful hyperparameter values by evaluating trials and using earlier results to guide later suggestions. It suits goals that can be expressed as a single numeric score, such as accuracy or error. section 5.4 section 5.4.1
Define an objective function that receives a trial, requests candidate values within specified ranges, and returns a score. Create a study with a minimize or maximize direction, then run the objective for a chosen number of trials. Optuna models the relationship between hyperparameters and score, using its predictions to suggest later trials; the technical details of that model are left aside. section 5.4.1 section 5.4.1
Figure 5.16 You supply Optuna with a function that does the three steps outlined in this diagram. Optuna uses its own algorithm to pick values for each hyperparameter, which you tell Optuna about using the trial.suggest functions; this function also informs Optuna about the minimum and maximum values you want to consider. You tell Optuna how many times to do this process, and each time it does, the black box gets better at picking new values to try.
The diagram traces the loop from defining an objective and search ranges to evaluating trials and improving later suggestions. section 5.4.1
A two-variable search
For f(x, y) = |(x − 3)(y + 2)|, request trial values for x and y from ranges of −10 to 10, then return the function value. A minimizing study can approach the minimum near x = 3 and y = −2. section 5.4.1
In neural-network training, candidate settings can include learning rate, momentum, layer count, and hidden-layer width. Tuning can be expensive: it may require training many models, so the available computational budget matters. section 5.4


