LoginSignup
20
18

More than 3 years have passed since last update.

Optunaでrandomのseedを固定する方法

Last updated at Posted at 2019-01-07

はじめに

おしっこちびる便利さのOptunaですが、実行するたびに結果が変わるのがどうしても気持ち悪く、固定する方法を載せている記事が見当たらなかったので調べて書きました。

code

公式のチュートリアルでは、下記の通りになっております。

def objective(trial):
    x = trial.suggest_uniform('x', -10, 10)
    return (x - 2) ** 2

study = optuna.create_study()
study.optimize(objective, n_trials=100)

このstudyをインスタンス化する部分(5行目)を、

study = optuna.create_study(sampler=optuna.samplers.RandomSampler(seed=123))

このように書き換えると、無事seedが固定され結果が毎度同じになります。

APIドキュメント



以上です。
ありがとうございました。

20
18
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
18