mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-10-04 12:50:44 +08:00
3.5 KiB
3.5 KiB
In [1]:
import optuna
def objective(trial):
x = trial.suggest_float("x", -100, 100)
y = trial.suggest_categorical("y", [-1, 0, 1])
if trial._trial_id % 2:
return None
return x**2 + y
if __name__ == "__main__":
study = optuna.create_study(
storage="sqlite:///db.sqlite3", # Specify the storage URL here.
study_name="quadratic-simple3"
)
study.optimize(objective, n_trials=7)
print(f"Best value: {study.best_value} (params: {study.best_params})")C:\Users\victo\AppData\Local\Programs\Python\Python311\Lib\site-packages\tqdm\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm
[I 2023-10-21 17:21:34,373] A new study created in RDB with name: quadratic-simple3
[I 2023-10-21 17:21:34,461] Trial 0 finished with value: 4357.102948257252 and parameters: {'x': 66.0007799064318, 'y': 1}. Best is trial 0 with value: 4357.102948257252.
[W 2023-10-21 17:21:34,508] Trial 1 failed with parameters: {'x': -21.941587885601493, 'y': -1} because of the following error: The value None could not be cast to float..
[W 2023-10-21 17:21:34,509] Trial 1 failed with value None.
[I 2023-10-21 17:21:34,566] Trial 2 finished with value: 2536.6789394289817 and parameters: {'x': 50.37538029066363, 'y': -1}. Best is trial 2 with value: 2536.6789394289817.
[W 2023-10-21 17:21:34,612] Trial 3 failed with parameters: {'x': -96.83015025022239, 'y': 0} because of the following error: The value None could not be cast to float..
[W 2023-10-21 17:21:34,613] Trial 3 failed with value None.
[I 2023-10-21 17:21:34,670] Trial 4 finished with value: 3591.471500742954 and parameters: {'x': -59.920543228036195, 'y': 1}. Best is trial 2 with value: 2536.6789394289817.
[W 2023-10-21 17:21:34,717] Trial 5 failed with parameters: {'x': -65.11319825521136, 'y': 1} because of the following error: The value None could not be cast to float..
[W 2023-10-21 17:21:34,717] Trial 5 failed with value None.
[I 2023-10-21 17:21:34,769] Trial 6 finished with value: 9478.234748213168 and parameters: {'x': -97.35622603723486, 'y': 0}. Best is trial 2 with value: 2536.6789394289817.
Best value: 2536.6789394289817 (params: {'x': 50.37538029066363, 'y': -1})
In [ ]: