I'm working with optuna for hyperparameter tuning of ML models in Python. While defining the objective function for tuning a Deep Learning model I tried to define a list of choices from which the trail.suggest_int
can pick up values from.
For example -
'batch_size': trial.suggest_int('batch_size', [16, 32, 64, 128, 256])
optuna documentation suggest that trial.suggest_int
should be in the following format
'some_param': trial.suggest_int('some_param', low, high, step)
my code looks something like below
def objective(trial):
DL_param = {
'learning_rate': trial.suggest_float('learning_rate', 1e-3, 1e-1),
'optimizer': trial.suggest_categorical('optimizer', ["Adam", "RMSprop", "SGD"]),
'h_units': trial.suggest_int('h_units', 50, 250, step = 50),
'alpha': trial.suggest_float('alpha', [0.001,0.01, 0.1, 0.2, 0.3]),
'batch_size': trial.suggest_int('batch_size', [16, 32, 64, 128, 256]),
}
DL_model = build_model(DL_param)
DL_model.compile(optimizer=DL_param['optimizer'], loss='mean_squared_error')
DL_model.fit(x_train, y_train, validation_split = 0.3, shuffle = True,
batch_size = DL_param['batch_size'], epochs = 30)
y_pred_2 = DL_model.predict(x_test)
return mse(y_test_2, y_pred_2, squared=True)
I'm facing problem in defining a list for the parameters 'alpha'
and 'batch_size'
. Is there a way? something like trial.suggest_categorical
can pick strings from the given list like in the above code
'optimizer': trial.suggest_categorical('optimizer', ["Adam", "RMSprop", "SGD"])
Any suggestions are welcome. Thanks in advance.