'keras fit does not return loss history for validation set

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


Solution 1:[1]

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

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 DPM