1

Why, when passing the validation_split parameter to the fit method, the history.history dictionary contains val_loss. And, when passing the validation_data parameter to the fit method, the history.history dictionary does not contain the key val_loss?

(1)

model.compile(
    optimizer=keras.optimizers.Adam(learning_rate=1e-3),
    loss='mse')
history = model.fit(
    x=[x1_train, x2_train],  # i have two inputs
    y=y_train,
    # ...
    validation_split=0.2)
history.history.keys()  # --> dict_keys(['loss', 'val_loss'])

(2)

model.compile(
    optimizer=keras.optimizers.Adam(learning_rate=1e-3),
    loss='mse')
history = model.fit(
    x=[x1_train, x2_train],
    y=y_train,
    # ...
    validation_data=([x1_val, x2_val], y_val))
history.history.keys()  # --> dict_keys(['loss'])
  • The validation data values are not attributed correctly. See https://www.tensorflow.org/api_docs/python/tf/keras/Model#fit – DPM Feb 11 '22 at 21:48
  • That is, the problem is that I have two inputs to the neural network? Is it not supported by default? – sc1ent13ter Feb 11 '22 at 22:03
  • It can for x, but not for the validation_data. For the validation_data you can't pass both a list with x1_val and x2_val and then y_val. You need to structure it like it says in the documentation – DPM Feb 11 '22 at 22:12
  • In this post: https://stackoverflow.com/questions/46308374/what-is-validation-data-used-for-in-a-keras-sequential-model they mention a very handy youtube video that explains quite well how to buld a validation dataset for keras: https://www.youtube.com/watch?v=dzoh8cfnvnI&ab_channel=deeplizard – DPM Feb 11 '22 at 22:13
  • 1
    [DRM](https://stackoverflow.com/users/13469674/dpm), thanks a lot! – sc1ent13ter Feb 11 '22 at 22:18
  • I'll post this as an answer so we can close this or you can close it – DPM Feb 11 '22 at 22:22

1 Answers1

0

The problem was that the input for validation_data was structured incorrectly, you can't pass both a list with x1_val and x2_val and then y_val. Take a look at the documentation here: https://www.tensorflow.org/api_docs/python/tf/keras/Model#fit and this video that explains how to create a validation dataset for keras: https://www.youtube.com/watch?v=dzoh8cfnvnI&ab_channel=deeplizard

DPM
  • 845
  • 7
  • 33