问题遇到的现象和发生背景
数据比较少,将LSTM单层改为多层能否提升预测的精准度
问题相关代码,请勿粘贴截图
model = Sequential()
if is_stateful:
# calculate new compatible batch size
for i in range(n_batch, 0, -1):
if train_X.shape[0] % i == 0 and test_X.shape[0] % i == 0:
if verbose and i != n_batch:
print(
"\n*In stateful network, batch size should be dividable by training and test sets; had to decrease it to %d." % i)
n_batch = i
break
model.add(LSTM(n_neurons, batch_input_shape=(n_batch, train_X.shape[1], train_X.shape[2]), stateful=True,
return_sequences=has_memory_stack))
if has_memory_stack:
model.add(LSTM(n_neurons, batch_input_shape=(n_batch, train_X.shape[1], train_X.shape[2]), stateful=True))
else:
model.add(LSTM(n_neurons, input_shape=(train_X.shape[1], train_X.shape[2])))
# model.add(Dropout(0.2))
#将一些网络层通过.add()堆叠起来,就构成了一个模型:
model.add(Dense(n_out_timestep))
model.compile(loss=loss_function, optimizer=optimizer_function,metrics=['acc'])