IniziaInizia gratis

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!

Questo esercizio fa parte del corso

Introduction to Deep Learning with Keras

Visualizza il corso

Istruzioni dell'esercizio

  • Import KerasClassifier from tensorflow.keras scikit_learn wrappers.
  • Create a KerasClassifier object providing the best parameters found.
  • Pass your model, features and labels to cross_val_score to perform cross-validation with 3 folds.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# 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())
Modifica ed esegui il codice