Reputation: 2305
This is how I segmented the data
(X, y), (X_test, y_test) = mnist.load_data()
X_train, X_val, y_train, y_val = train_test_split(X,
y,
test_size=0.1,
random_state=1)
The below code plots X_train and X_val, I would like to add X_test the plot
history = model.fit(
x= X_train,
y= y_train,
epochs = 10,
validation_data = (X_val, y_val),
batch_size = 128
)
from matplotlib import pyplot as plt
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'val'], loc='upper left')
plt.show()
Is it also possible to plot the test_loss
on top of this to get an overview of all three on the same plot?
There is no history.history['test_loss']
.
Upvotes: 0
Views: 2563
Reputation: 1127
You did not calculate test_loss yet. You first need to predict some labels using X_test and then calculate the loss based on the predicted values and y_test. Alternatively, you can use evaluate to do that directly:
test_loss = model.evaluate(X_test, y_test)
You cannot plot them together since test_loss is a single value that is calculated once at the end of training and not every epoch like validation.
Nevertheless, you should not use X_test and y_test in training as you will have trained on the whole available data so you can't test anymore.
X_test and y_test are to be used solely at the end of all the steps to test the performance of the model.
The validation data serves the purpuse of "test data" while you are training. After you have done all the training and optimization you can then retrain the network on the combined dataset of train ad validation, and use the resulting network to test it's performace on the test dataset (X_test, y_test)
Upvotes: 1