时间序列数据时用于LSTM的输入

时间:2018-07-10 15:08:24

标签: python-3.x tensorflow keras deep-learning lstm

我有一个大小为(1152,151)的(非文本)数据集。我希望将其分为8批,每批包含144个样本,用于在Keras中训练LSTM网络。我将要发送到LSTM的数据重塑为(8,144,151)。这是正确的输入形状吗?因为当我将其作为输入发送并在该层以及下一个LSTM层也具有return_sequences = False时,出现了错误:

  

期望n_dim = 3,得到n_dim = 2。

X_train = X_train.reshape((8,144,151))
def deepmodel():
  model = Sequential()
  model.add(LSTM(8,input_shape=(144,151),return_sequences=False))
  model.add(LSTM(8,return_sequences=False))
  model.add(Dense(8))
  model.add(Activation('softmax'))
  adam=Adam()
  model.compile(loss = 'categorical_crossentropy', optimizer = adam)
return model

1 个答案:

答案 0 :(得分:2)

您将在model.fit(...., batch_size=8)中设置批次大小。查看下面的示例,它应该清除您的错误消息。如果您要寻找多个时滞,请务必查看这个精彩的blog post

X_train = X_train.reshape((X_train.shape[0], 1, X_train.shape[1]))
def deepmodel():
  model = Sequential()
  model.add(LSTM(8,input_shape=(train_X.shape[1], train_X.shape[2]), return_sequences=False))
  model.add(LSTM(8,return_sequences=False))
  model.add(Dense(8))
  model.add(Activation('softmax'))
  adam=Adam()
  model.compile(loss = 'categorical_crossentropy', optimizer = adam)
return model