【发布时间】:2018-10-28 11:47:59
【问题描述】:
我很难确定 LSTM 网络的尺寸。
所以我有以下数据:
train_data.shape
(25391, 3) # to be read as 25391 timesteps and 3 features
train_labels.shape
(25391, 1) # to be read as 25391 timesteps and 1 feature
所以我认为我的输入维度是(1, len(train_data), train_data.shape[1]),因为我计划提交 1 批。但我收到以下错误:
Error when checking target: expected lstm_10 to have 2 dimensions, but got array with shape (1, 25391, 1)
这是型号代码:
model = Sequential()
model.add(LSTM(1, # predict one feature and one timestep
batch_input_shape=(1, len(train_data), train_data.shape[1]),
activation='tanh',
return_sequences=False))
model.compile(loss = 'categorical_crossentropy', optimizer='adam', metrics = ['accuracy'])
print(model.summary())
# as 1 sample with len(train_data) time steps and train_data.shape[1] features.
model.fit(x=train_data.values.reshape(1, len(train_data), train_data.shape[1]),
y=train_labels.values.reshape(1, len(train_labels), train_labels.shape[1]),
epochs=1,
verbose=1,
validation_split=0.8,
validation_data=None,
shuffle=False)
输入尺寸应该是什么样的?
【问题讨论】:
标签: python tensorflow machine-learning keras lstm