Chapter 15 Understand Model Behavior During Training By Plotting History Flashcards

1
Q

History is a Keras callback. True/False? P 108

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does History do, in Keras? P 108

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can we visualize the history of learning based on each epoch and evaluation metric? P 109

A
# 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()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does history.history.keys() do? P 109

A

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’])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The “history_” attribute in SciKeras, works only when the model is fitted first. True/False? External

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly