0

I am trying to tune hyperparameter on the KerasRegressor

However, i only get the result of NaN's which is shown below, may i know what cause the issue?

everything works fine when i try to compile my model... but the scoring for the best parameters it always show NaNs, metrics that i used is RMSE enter image description here

code snippet at below:

def create_model(optimizer,activation,lstm_unit_1,lstm_unit_2,lstm_unit_3, init='glorot_uniform'):
    model = Sequential()
    model.add(Conv1D(lstm_unit_1, kernel_size=1, activation=activation, input_shape = (trainX.shape[1], trainX.shape[2])))
    model.add(GRU(lstm_unit_2, activation = activation, return_sequences=True, input_shape = (trainX.shape[1], trainX.shape[2])))
    model.add(GRU(lstm_unit_3, activation = activation, return_sequences=True, input_shape = (trainX.shape[1], trainX.shape[2])))
    model.add(Dense(units = 1))
    model.add(Flatten())
    model.compile(optimizer = optimizer, loss = 'mse', metrics = ['mean_squared_error'])
    return model
model = tf.keras.wrappers.scikit_learn.KerasRegressor(build_fn = create_model, 
                                                      epochs = 150, 
                                                      verbose=False)
batch_size = [16,32,64,128]
lstm_unit_1 = [128,256,512]
lstm_unit_2 = lstm_unit_1.copy()
lstm_unit_3 = lstm_unit_1.copy()
optimizer = ['SGD','Adam','Adamax','RMSprop']
activation = ['relu','linear','sigmoid',]
param_grid = dict(lstm_unit_1=lstm_unit_1,
                  lstm_unit_2=lstm_unit_2,
                  lstm_unit_3=lstm_unit_3,
                  optimizer=optimizer,
                  activation=activation,
                  batch_size = batch_size)

warnings.filterwarnings("ignore")
random = RandomizedSearchCV(estimator=model, param_distributions=param_grid, n_jobs=-1, scoring='neg_mean_squared_error')
random_result = random.fit(trainX,trainY)

print(random_result.best_score_)
print(random_result.best_params_)
Chuen Yik Kang
  • 83
  • 1
  • 11
  • just try out keras sk-learn wrapper around the model. As shown [here](https://www.kaggle.com/christianlillelund/tuning-a-keras-dnn-with-randomizedsearchcv) – nipun Jan 13 '22 at 03:53
  • did already include wrapper around my model, but it computes NaN's value, maybe can you have a look at RandomizedSearchCV param? – Chuen Yik Kang Jan 13 '22 at 04:32

0 Answers0