adriangb / scikeras

Scikit-Learn API wrapper for Keras.
https://www.adriangb.com/scikeras/
MIT License
239 stars 47 forks source link

How pass a number of neurons in the model for KerasClassifier :Invalid parameter neurons for estimator KerasClassifier. #318

Open AntonioConstantino opened 5 months ago

AntonioConstantino commented 5 months ago

Error: Check the list of available parameters with estimator.get_params().keys()

In the function define a neurons parameter, but when you pass through KerasClassifier the parameters do not allow that optimization or the passing of that parameter, for your best guess please

model :

def build_model(optimizer='adam', neurons=60): model=Sequential() model.add(Embedding(NUM_PALABRAS, neurons, input_length=longitud_maxima)) model.add(Dropout(0.2)) model.add(Flatten()) model.add(Dense(12, activation='relu')) model.add(Dropout(0.3)) model.add(Dense(len(generos), activation='softmax')) model.compile(loss='categorical_crossentropy', optimizer=optimizer, metrics=['accuracy']) return model

neurons = [30, 60, 90] batch_size = [10] optimizer = ['adam', 'rmsprop']

param_grids = dict(neurons=neurons, batch_size=batch_size, optimizer=optimizer) model = KerasClassifier(build_fn=build_model, verbose=2)

grid = GridSearchCV(estimator=model, param_grid=param_grids, n_jobs=-1) result = grid.fit(X_train, y_train,)

print("Best: {} using {}".format(result.bestscore, result.bestparams))