LSTM模型预测效果不佳
LSTM model has poor prediction results
#根据气象数据和历史径流预测未来径流
Streamflow=pd.read_csv('###.csv', delimiter=',')
x = Streamflow.drop('Q',axis=1)
Y = Streamflow['Q']
X = np.array(x)
y = np.array(Y)
test_size = int(len(X) * 0.15)
valid_size = int(len(X) * 0.15)
train_size= len(X) - (valid_size+test_size)
y_train, y_valid, y_test = y[0:train_size], y[train_size:train_size+valid_size], y[-test_size:]
X_train, X_valid, X_test = X[0:train_size], X[train_size:train_size+valid_size], X[train_size+valid_size:]
X_train = np.reshape(X_train, (X_train.shape[0], 1, X_train.shape[1]))
X_valid = np.reshape(X_valid, (X_valid.shape[0], 1, X_valid.shape[1]))
X_test = np.reshape(X_test, (X_test.shape[0], 1, X_test.shape[1]))
input=X_train[1:]
input_shape=X_train.shape[1:]
print (y_train.shape, y_valid.shape, y_test.shape)
model = Sequential()
model.add(LSTM(150, input_shape=X_train.shape[1:], activation='relu',return_sequences=True))
model.add(Dropout(0.3))
model.add(LSTM(300, activation='relu'))
model.add(Dropout(0.3))
model.add(Dense(200, activation='relu'))
model.add(Dropout(0.6))
model.add(Dense(1, activation='relu'))
optimizer = tf.keras.optimizers.SGD(learning_rate=e_LR)
model.compile(optimizer=optimizer,loss='MeanAbsoluteError')
history = model.fit(X_train, y_train, epochs=e_epoch, batch_size=e_batch_size, verbose=0, validation_data=(X_valid, y_valid), shuffle=True)
enter image description here 这是模型损失和结果。训练期和验证期的结果还可以,但是测试期的结果太差了。我应该如何修改模型? (数据没有归一化,因为归一化后的预测是一条直线。)
对不起,我的声望不够,无法直接发表评论。可以尝试以下三种方案: 1.尽可能降低学习率 2.降低模型复杂度,比如降低LSTM的hidden size。 3.增加训练轮数