![]() |
VOOZH | about |
Hyperparameter tuning is done to increase the efficiency of a model by tuning the parameters of the neural network. Some scikit-learn APIs like GridSearchCV and RandomizedSearchCV are used to perform hyper parameter tuning.
In this article, you'll learn how to use GridSearchCV to tune Keras Neural Networks hyper parameters.
Code:tf.keras.wrappers.scikit_learn.KerasClassifier(
build_fn=None, **sk_params
)
Import the dataset using which we'll predict if a customer stays or leave.
To use the KerasClassifier wrapper, we will need to build our model in a function which needs to be passed to the build_fn argument in the KerasClassifier constructor.
Code: Code: create the object of KerasClassifier classNow we will create the dictionary of the parameters we want to tune and pass as an argument in GridSearchCV.
Code:The best_score_ member gives the best score observed during the optimization procedure and the best_params_ describes the combination of parameters that achieved the best results.
Code:Accuracy: 0.80325
Best Params: {'batch_size': 20, 'nb_epoch': 200, 'unit': 15}