0

epoch vs loss plot

I am getting above epoch vs loss plot while training on time series forecasting in keras 2.2.4. Model configuration 1 lstm layer, 1 dense layer, num epochs - 64. On some set of configuration I am getting right plot with just two curves one for validation set and one for training loss dataset while on some configuration I am getting this absurd plot shown in image. I am not able to understand why this is happening? My code --

def train(trainingData, config):
    inputShape, numNode, numEpoch, batchSize = config
    if nDiff > 0:
            trainingData = np.array(difference(trainingData))
    trainX, trainY = trainingData[:, :-1], trainingData[:, -1]
    trainX = trainX.reshape((trainX.shape[0], trainX.shape[1], 1))
    model = Sequential()
    model.add(LSTM(numNode, activation = 'relu', input_shape = (inputShape, 1)))
    #model.add(Dense(4, activation = 'relu'))
    model.add(Dense(1))
    model.compile(loss = 'mse' , optimizer = 'adam')
    history = model.fit(trainX, trainY,  validation_split = 0.2, epochs = numEpoch, batch_size = batchSize, verbose = 0, shuffle = True)
    # summarize history for loss
    plt.plot(history.history['loss'])
    plt.plot(history.history['val_loss'])
    plt.title('model loss')
    plt.ylabel('loss')
    plt.xlabel('epoch')
    plt.legend(['train', 'test'], loc='upper left')
    plt.savefig(modelName + "ind")         
    return model
cat
  • 31
  • 1
  • 7

2 Answers2

0

Do you have metrics=['...'] in you model.compile() by any chance? If so, the graph probably shows the additional metric besides your original loss.

tYAt1YBWFY
  • 304
  • 2
  • 8
  • i have added my code there is no metrics in model.compile(). If don't save the epoch vs loss plot and than in pyplot popup the plot is shown perfectly fine. This issue only arises when plot.save() is used – cat Mar 10 '19 at 10:48
0

do

plt.close('all')

after you are done with the plotting of one plot or before you start each plotting

i.e.,

Replace

plt.savefig(modelName + "ind")         

with

plt.savefig(modelName + "ind")   
plt.close('all')
mujjiga
  • 16,186
  • 2
  • 33
  • 51