Chapter 15 Understand Model Behavior During Training By Plotting History Flashcards
History is a Keras callback. True/False? P 108
True. Keras provides the capability to register callbacks when training a deep learning model. One of the default callbacks that is registered when training all deep learning models is the History callback
What does History do, in Keras? P 108
It records training metrics for each epoch. This includes the loss and the accuracy (for classification problems) as well as the loss and accuracy for the validation dataset, if one is set.
How can we visualize the history of learning based on each epoch and evaluation metric? P 109
# Checkpoint the weights when validation accuracy improves from keras.models import Sequential from keras.layers import Dense from keras.callbacks import ModelCheckpoint import matplotlib.pyplot as plt import numpy from sklearn.datasets import load_breast_cancer, load_iris,load_diabetes dataset = load_breast_cancer(as_frame=True) X = dataset.data Y = dataset.target model = Sequential() model.add(Dense(12, input_dim=30,activation= "relu" )) model.add(Dense(8, activation= "relu" )) model.add(Dense(1, activation= "sigmoid" )) # Compile model model.compile(loss= "binary_crossentropy" , optimizer= "adam" , metrics=[ "accuracy" ]) # Fit the model history=model.fit(X, Y, validation_split=0.2, epochs=15, batch_size=10, verbose=0) # summarize history for accuracy plt.plot(history.history[ "accuracy" ]) plt.plot(history.history[ "val_accuracy" ]) plt.title( "model accuracy" ) plt.ylabel( "accuracy" ) plt.xlabel( "epoch" ) plt.legend([ "train" , "test" ], loc= "best" ) plt.show() # summarize history for loss plt.plot(history.history[ "loss" ]) plt.plot(history.history[ "val_loss" ]) plt.title( "model loss" ) plt.ylabel( "loss" ) plt.xlabel( "epoch" ) plt.legend([ "train" , "test" ], loc= "best" ) plt.show()
What does history.history.keys() do? P 109
List the metrics collected in a history object. for example, in classification it returns the below dict keys:
dict_keys([‘loss’, ‘accuracy’, ‘val_loss’, ‘val_accuracy’])
The “history_” attribute in SciKeras, works only when the model is fitted first. True/False? External
True
USE OF FIT IS A MUST BEFORE USING ANY ATTRIBUTE OF SCIKERAS MODELS
Using Cross_val_score DOES NOT fit the model to data it just creates a replica of the model to calculate the scores, so this attribute would NOT work after using cross_val_score on the data.