接着上次的验证LSTM模型的性能
参数设置(hidden unit=15, Adam, N=5, earlystop策略, 单层)
结果:
- LSTM的解不稳定,多次运行结果不一致。
- LSTM的性能不如ANN, 最多达到r2_score=0.966,但比SVR要好
- earlystop策略挺不错,通常10个迭代左右就停止了,说明该数据集容易过拟合
# 5. LSTM模型的预测结果:
#5.1 准备LSTM的数据(samples, time-lag, features)
X_tr_t = X_train.reshape(X_train.shape[0], N, 1)
X_tst_t = X_test.reshape(X_test.shape[0], N, 1)
#5.2 构建LSTM模型
K.clear_session()
model_lstm = Sequential()
model_lstm.add(LSTM(units=30, input_shape=(N, 1), activation='relu', kernel_initializer='lecun_uniform', return_sequences=False))
model_lstm.add(Dense(1))
model_lstm.compile(loss='mean_squared_error', optimizer='adam')
#这里用了早停方法
early_stop = EarlyStopping(monitor='loss', patience=5, verbose=1