keras-team/keras-applications

Cannot clone object <keras.wrappers.scikit_learn.KerasRegressor object at 0x7fdc9c3ba550>

ruchi571993 opened this issue · 1 comments

Trying to hypertune ANN but getting an error while using fit..(grid1.fit(X_train, y_train))
Below is the code

def create_model(dropout_rate,weight_constraint,optimizer,init,layers,activation):
model = Sequential()
model.add(Dense(nodes, input_dim=171, kernel_initializer=init, activation='relu', kernel_constraint=maxnorm(weight_constraint)))
model.add(Dropout(dropout_rate))
model.add(Dense(1, kernel_initializer=init, activation='relu'))

model.compile(loss='mse', optimizer=optimizers, metrics=['mean_absolute_error'])
return model

model = KerasRegressor(build_fn=create_model, verbose=0)

#hyperparameters
layers = [[50],[50, 20], [50, 30, 15], [70,45,15,5]]
optimizers = ['rmsprop', 'adam']
dropout_rate = [0.1, 0.2, 0.3, 0.4]
init = ['glorot_uniform', 'normal', 'uniform']
epochs = [150, 500]
batches = [5, 10, 20]
weight_constraint = [1, 2, 3]
param_dist = dict(optimizer=optimizers,
layers=layers,
dropout_rate=dropout_rate,
epochs=epochs,
batch_size=batches,
weight_constraint=weight_constraint,
init=init
)

grid1 = RandomizedSearchCV(estimator=model,param_distributions=param_dist,n_jobs=-1, cv=6)

grid1.fit(X_train, y_train)

`

Had the same Problem. Try to
Change
layers = [[50],[50, 20], [50, 30, 15], [70,45,15,5]]
To
layers = [(50), (50,20), (50,30,15), (70,45,15,5)]

That worked for me.