ASDFG6324
2022-03-27 11:33
采纳率: 0%
浏览 38

LSTM如何将单层改为多层

问题遇到的现象和发生背景

数据比较少,将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'])
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果

1条回答 默认 最新

相关推荐 更多相似问题