使用 Optuna 微调时使超参数加起来为 1
Making hyperparameters add up to 1 when fine tuning using Optuna
我有一个看起来像这样的函数:
def fine_tuning(x,y,model1,model2,model3,trial):
pred1 = model1.predict(x)
pred2 = model2.predict(x)
pred3 = model3.predict(x)
h1 = trial.suggest_float('h1', 0.0001, 1, log = True)
h2 = trial.suggest_float('h1', 0.0001, 1, log = True)
h3 = trial.suggest_float('h1', 0.0001, 1, log = True)
pred = pred1 * h1 + pred2 * h2 + pred3 * h3
return mean_absolute_error(y, pred)
此函数的问题在于 h1+h2+h3 != 1。我该如何更改此函数才能使超参数之和 = 1?
基本上,您正在寻找 h1、2、3 的狄利克雷分布。以下是关于如何为 Optuna 实现该分布的指南:https://optuna.readthedocs.io/en/latest/faq.html#how-do-i-suggest-variables-which-represent-the-proportion-that-is-are-in-accordance-with-dirichlet-distribution
我有一个看起来像这样的函数:
def fine_tuning(x,y,model1,model2,model3,trial):
pred1 = model1.predict(x)
pred2 = model2.predict(x)
pred3 = model3.predict(x)
h1 = trial.suggest_float('h1', 0.0001, 1, log = True)
h2 = trial.suggest_float('h1', 0.0001, 1, log = True)
h3 = trial.suggest_float('h1', 0.0001, 1, log = True)
pred = pred1 * h1 + pred2 * h2 + pred3 * h3
return mean_absolute_error(y, pred)
此函数的问题在于 h1+h2+h3 != 1。我该如何更改此函数才能使超参数之和 = 1?
基本上,您正在寻找 h1、2、3 的狄利克雷分布。以下是关于如何为 Optuna 实现该分布的指南:https://optuna.readthedocs.io/en/latest/faq.html#how-do-i-suggest-variables-which-represent-the-proportion-that-is-are-in-accordance-with-dirichlet-distribution