I am using the awesome scikit-optimize toolbox for hyperparameter optimization. My goal is to compare keras and scikit-learn models.
According to the example https://scikit-optimize.github.io/stable/auto_examples/sklearn-gridsearchcv-replacement.html#sphx-glr-auto-examples-sklearn-gridsearchcv-replacement-py only scikit learn models had been used. Trying something like the following code does not allow to integrate the keras mode in the BayesSearchCV.
# Function to create model, required for KerasRegressor
def create_model(optimizer='rmsprop', init='glorot_uniform'):
# create model
model = Sequential()
model.add(Dense(12, input_dim=8, kernel_initializer=init, activation='relu'))
model.add(Dense(8, kernel_initializer=init, activation='relu'))
model.add(Dense(1, kernel_initializer=init, activation='linear'))
# Compile model
model.compile(loss='mse', optimizer=optimizer, metrics=['r2'])
return model
model = KerasRegressor(build_fn=create_model, verbose=0)
NN_search = {
'model': [model()],
'model__optimizers': optimizers,
'model__epochs' : epochs,
'model__batch_size' : batches,
'model__init' : init
}
Has anyone managed to merge a KerasClassifier/Regressor into BayesSearch CV?