You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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_}")
The text was updated successfully, but these errors were encountered:
Adding GridSearch for epochs and other tune parameters
The text was updated successfully, but these errors were encountered: