MulaiMulai sekarang secara gratis

Hands-on with Optuna

Use Optuna to optimize the hyperparameters of a simple function.

In practice, you would want to optimize an objective function which is expensive or time-consuming to evaluate. As a result, you want to find reasonable hyperparameters in as few trials as possible.

For convenience, you will use a predefined objective function here instead which can be evaluated near-instantaneously:

$$f(x,y) = 2*(1-x)^2 + (y-x)^2$$

The metric() function is defined in your environment.

For this exercise, x and y are the hyperparameters that you optimize for.

Latihan ini adalah bagian dari kursus

Deep Reinforcement Learning in Python

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

study = optuna.create_study()

def objective(trial: optuna.Trial):
    # Declare hyperparameters x and y as uniform
    x = ____
    y = ____
    
    value = metric(x, y)
    return value
Edit dan Jalankan Kode