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

Add hyperopt #6

Open
TilenRupar opened this issue Aug 28, 2023 · 0 comments
Open

Add hyperopt #6

TilenRupar opened this issue Aug 28, 2023 · 0 comments

Comments

@TilenRupar
Copy link
Collaborator

TilenRupar commented Aug 28, 2023

Adding GridSearch for epochs and other tune parameters

from tensorflow.keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import GridSearchCV

# Define a function to create a Keras model with variable hyperparameters
def create_model(optimizer='adam'):
   model = tf.keras.models.Sequential([...])
   model.compile(optimizer=optimizer, loss='binary_crossentropy', metrics=['accuracy'])
   return model

# Wrap the model with KerasClassifier
model = KerasClassifier(build_fn=create_model, verbose=0)
 
# Define the grid of hyperparameters to search
param_grid = {'batch_size': [10, 20, 50],
              'epochs': [10, 50, 100],
              'optimizer': ['adam', 'rmsprop']}
 
# Perform GridSearchCV
grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1, cv=3)
grid_result = grid.fit(X_train, y_train)

# Review the best parameters from the search
print(f"Best: {grid_result.best_score_} using {grid_result.best_params_}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant