0

时代与损失图

在 keras 2.2.4 中进行时间序列预测训练时,我正在超越 epoch vs loss plot。模型配置 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
4

2 回答 2

0

你有metrics=['...']没有model.compile()机会?如果是这样,该图可能会显示除原始损失之外的其他指标。

于 2019-03-10T10:41:48.697 回答
0

plt.close('all')

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

IE,

代替

plt.savefig(modelName + "ind")         

plt.savefig(modelName + "ind")   
plt.close('all')
于 2019-03-10T10:51:44.380 回答