时间序列预测在喀拉拉邦的损失与时代图

时间:2019-03-10 10:28:34

标签: matplotlib keras keras-2

epoch vs loss plot

当我在keras 2.2.4中进行时间序列预测训练时,我超越了时代与损失的图。模型配置1 lstm层,1致密层,num epochs-64。在某些配置集上,我得到了正确的图,只有两条曲线,一条用于验证集,一条用于训练损耗数据集,而在某些配置上,我得到了这个荒谬的图在图像中。我不明白为什么会这样? 我的代码-

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

2 个答案:

答案 0 :(得分:0)

val squared = udf((s: Long) => s * s) 中是否有metrics=['...']?如果是这样,该图可能会显示除原始损失之外的其他指标。

答案 1 :(得分:0)

plt.close('all')

完成一个图的绘制后或开始每个图之前

替换

plt.savefig(modelName + "ind")         

使用

plt.savefig(modelName + "ind")   
plt.close('all')