Training with cross-validation
Time to train your model with the best parameters found: 0.001 for the learning rate, 50 epochs, a 128 batch_size and relu activations.
The create_model()
function from the previous exercise is ready for you to use. X
and y
are loaded as features and labels.
Use the best values found for your model when creating your KerasClassifier
object so that they are used when performing cross_validation.
End this chapter by training an awesome tuned model on the breast cancer dataset!
This exercise is part of the course
Introduction to Deep Learning with Keras
Exercise instructions
- Import
KerasClassifier
fromtensorflow.keras
scikit_learn wrappers. - Create a
KerasClassifier
object providing the best parameters found. - Pass your
model
, features and labels tocross_val_score
to perform cross-validation with 3 folds.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import KerasClassifier from tensorflow.keras wrappers
from tensorflow.keras.wrappers.____ import ____
# Create a KerasClassifier
model = ____(build_fn = create_model(learning_rate = ____, activation = ____), epochs = ____,
batch_size = ____, verbose = 0)
# Calculate the accuracy score for each fold
kfolds = cross_val_score(____, ____, ____, cv = ____)
# Print the mean accuracy
print('The mean accuracy was:', kfolds.mean())
# Print the accuracy standard deviation
print('With a standard deviation of:', kfolds.std())