'Missing val_acc after fitting sequential model
I am missing information about the 'val_acc' attribute when I fit a compiled sequential model.
I have a sequential model that is compiled with 'accuracy' metrics
model = Sequential()
model.add(Dense(12, input_dim=8, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
and I expect to get info about ['acc', 'loss', 'val_acc', 'val_loss'] attributes after fitting this neural network
history = model.fit(X, Y, epochs=100, batch_size=10)
But the information about val_acc is missing on the progress bar
Epoch 14/100
768/768 [==============================] - 0s 212us/step - loss: 0.4356 - acc: 0.7969
Epoch 15/100
768/768 [==============================] - 0s 219us/step - loss: 0.4388 - acc: 0.8034
Epoch 16/100
768/768 [==============================] - 0s 220us/step - loss: 0.4398 - acc: 0.7956
And it's missed also in object history
>>> print (history.history.keys())
dict_keys(['loss', 'acc'])
How do I get the missing attributes ('val_acc', 'val_loss') when training a neural network?
Solution 1:[1]
history = model.fit(X, Y, epochs=100, batch_size=10)
Validation data is missing in your fit
method, so it has no way to calculate validation metrics.
Either split some of your train data into validation set and pass it explicitly via
validation_data
argument of fit methodor
Use
validation_split
argument of fit method to use some % of your train data as validation data. Example:validation_split=0.15
will use 15% of your train data as validation data.
Solution 2:[2]
For anyone coming across this in the future: make sure that your validation generator is not empty!
In my case, I forgot to add data into my validation generator variable and was confused for quite a while, wondering why I wasn't getting my validation loss or accuracy, because Keras and Python stay silent even if you pass in a generator which does nothing
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mujjiga |
Solution 2 | Jeff Chen |