I tried plotting the loss terms of my model, while using keras. I got the plot for 'loss' but 'val_loss' throws up a keyword error: I tried searching the internet and got this link : link to a previous post. But in this post they are using checkpoints and callbacks. While I have not implemented such features (It was not included in the tutorial I am following). Can someone help me getting around these errors! Thanks.
KeyError: 'val_loss'
Code:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import math
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_squared_error
from keras.models import Sequential
from keras.layers import Dense, Activation, Dropout
from keras.layers import LSTM
model = Sequential()
model.add(LSTM(128, input_shape=(1, step_size)))
model.add(Dropout(0.1)) # randomly select neurons to be ignored during training.
model.add(Dense(64))
model.add(Dense(1))
model.add(Activation('linear'))
model.summary()
model.compile(loss='mean_squared_error', optimizer='adam')
history = model.fit(trainX, trainY, epochs=1000, batch_size=25, verbose=2)
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()
And also the same for accuracy: Note I tried changing the keyword 'acc' to 'accuracy' as mentioned in the previous post. But the same error pops up for that too: link
Error: KeyError: 'acc'
acc = history.history['acc']
val_acc = history.history['val_accuracy']
plt.plot(history.history['acc'])
plt.plot(history.history['val_accuracy'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'val'], loc='upper left')
plt.show()