Skip to content
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

Error: model must be a callable, a Keras Model instance or None #20893

Open
tserversbfs opened this issue Feb 12, 2025 · 1 comment
Open

Error: model must be a callable, a Keras Model instance or None #20893

tserversbfs opened this issue Feb 12, 2025 · 1 comment
Assignees
Labels

Comments

@tserversbfs
Copy link

I am way over my head... I keep getting this error and I have no idea what it means. I am hoping someone can help me fix this error. I have searched for "must be a callable, a Keras Model instance or None" and have found nothing.

def build_model(self):
    model = Sequential()
    model.add(Dense(64, input_dim=7, activation='relu'))
    model.add(Dropout(0.2))
    model.add(Dense(32, activation='relu'))
    model.add(Dense(1, activation='sigmoid'))
    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
    return model

def train_model(self, X, y):
    # Wrap the Keras model for use in scikit-learn
    keras_model = KerasClassifier(model=self.build_model, epochs=10, batch_size=32, verbose=0)

    # Perform hyperparameter tuning
    param_grid = {
        'model__epochs': [10],
        'model__batch_size': [32]
    }
    grid_search = GridSearchCV(estimator=keras_model, param_grid=param_grid, cv=3, scoring='accuracy', error_score='raise')
    grid_search.fit(X, y)

    # Set the best model
    self.model = grid_search.best_estimator_

thank you for you patience.

@Surya2k1
Copy link
Contributor

@tserversbfs , There was an issue with wrapping a compiled model with SKLearn wrappers which was addressed in this PR #20888.
I think this issue also might probably relevant to the same. Can you please check with latest nightly and if still issue exists providing replicable code snippet might help to look into the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants