-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with KerasClassifier #112
Comments
Thank for for the report and the kind words! I haven't had a chance to test it (I will do so in a couple of hours), but I think this may be the same bug/issue as #78. If so, it should be fixed by #88, which should happen soon. In the meantime, maybe using |
Worked perfectly. Thank you very much for your attention. |
As of last night, it should be fixed in master. That said, there are a couple of changes I would make:
model = KerasClassifier(model=build_model, verbose=1) Also, SciKeras can now compile models for you, which allows you to do hyperparameter tuning of optimizer learning rates, for example: def build_model(optimizer): # defaults no longer needed
model = Sequential()
model.add(Flatten(input_shape=(28, 28)))
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(10, activation='softmax'))
return model # return an un-compiled model
model = KerasClassifier(
model=build_model,
verbose=1,
loss="sparse_categorical_crossentropy", # you need to specify the loss here
optimizer__learning_rate=0.02, # no optimizer specified, default is rmsprop
)
grid = GridSearchCV(estimator=model, param_grid={"optimizer__learning_rate": [0.1, 0.01, 0.0001]})
result = grid.fit(X, y) |
I am still evaluating SciKeras with the |
Hi @adriangb, I applied the suggested updates and they worked (Version: 0.2.0). With the Now with |
Yes, that is because SciKeras no longer introspects your model's loss function. To make
def build_model():
model = Sequential()
model.add(Flatten(input_shape=(28, 28)))
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(10, activation='softmax'))
return model
model = KerasClassifier(
model=build_model,
loss="categorical_crossentropy", # pass categorical_crossentropy
) This applies even if you are compiling your own model: def build_model():
model = Sequential()
model.add(Flatten(input_shape=(28, 28)))
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(10, activation='softmax'))
model.compile(
loss="categorical_crossentropy", # loss matches constructor loss
optimizer="sgd", # override default optimizer
metrics=["accuracy"] # add a metric
)
return model
model = KerasClassifier(
model=build_model,
loss="categorical_crossentropy", # pass categorical_crossentropy
) |
I'll close this issue since it seems like it's resolved. Let me know if there is any followup. Thanks for the bug report! |
Hi @adriangb,
congratulations for the work.
I am having a problem with a dataset that I am using in my work.
KerasRegressor
is working perfectly with me, butKerasClassifier
presented a problem that did not happen withkeras.wrappers.scikit_learn
.I took a simple example with the mnist dataset and the problem persisted.
If I change the import
scikeras
tokeras.wrappers.scikit_learn
the code works perfectly.Shapes of X and y:
X
(70000, 28, 28)
y
(70000,)
Thanks a lot for attention.
The text was updated successfully, but these errors were encountered: