1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

optunaで探索済みのデータをtrialに渡して重要度を評価する方法

Last updated at Posted at 2022-10-22

表題の通りです.

具体的には,

  1. trial.create_trialでデータからtrialを作成
  2. study.add_trialsstudyにデータを追加

create_trialには各変数の分布型を指定する必要があります.(言い換えると分布型は探索空間を定義するものであり,当然ですが分布型によって結果が変わります.)

import optuna
import numpy as np

LB, UB = -5, 5
study = optuna.create_study()

rng = np.random.RandomState(42)
samples = rng.random((50, 2)) * (UB - LB) + LB
study.add_trials([
    optuna.trial.create_trial(
        params=dict(x=x, y=y),
        distributions=dict(
            x=optuna.distributions.FloatDistribution(LB, UB),
            y=optuna.distributions.FloatDistribution(LB, UB),
        ),
        value=(x ** 2 + (y / 10) ** 2)
    )
    for x, y in samples
])
optuna.importance.get_param_importances(
    study,
    evaluator=optuna.importance.FanovaImportanceEvaluator(),
)

実際に実行すると以下のような結果が得られます.

OrderedDict([('x', 0.9508186441212698), ('y', 0.049181355878730224)])

与えたデータは $x^2 + y^2/100$であるため,$x$がより重要であるという情報は正しいです.

1
1
0

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?