在使用tensorflow.keras训练多输入多输出预测模型时碰到loss不断减小,val_loss不变,甚至震荡的情况
loss变化趋势如下:(忘记保存图片了,只用手机拍了一下)
但是该模型预测结果勉强还行,结果如下:
我的模型结构如下:
Xtrain.shape, Xtest.shape, Ytrain.shape, Ytest.shape为(2036, 60, 6) (400, 60, 6) (2036, 60, 6) (400, 60, 6)
model = keras.models.Sequential()
model.add(keras.layers.LSTM(40, input_shape=(Xtrain.shape[1:]), return_sequences=True))
model.add(keras.layers.Dropout(0.1))
model.add(keras.layers.LSTM(30, return_sequences=True, kernel_regularizer=keras.regularizers.l2(0.002)))
model.add(keras.layers.Dropout(0.1))
model.add(keras.layers.LSTM(30, return_sequences=True, kernel_regularizer=keras.regularizers.l2(0.002)))
model.add(keras.layers.TimeDistributed(keras.layers.Dense(Ytrain.shape[2])))
model.compile(optimizer=keras.optimizers.Adam(lr=0.002, amsgrad=True), loss='mse', metrics='accuracy') # mae: mean_absolute_error
model.summary()
history = model.fit(
Xtrain, Ytrain,
validation_data=(Xtest, Ytest),
batch_size=8,
epochs=600,
verbose=1)
看其他博客说这种情况是过拟合,但是我把正则项L2加大后,loss在大概10个epochs左右就稳定了不变了,导致预测结果也很差,请问这种情况应该怎么调整模型啊