keras input shape怎么写

大家好!
我在尝试使用Keras下面的LSTM做深度学习,我的数据是这样的:X-Train:30000个数据,每个数据6个数值,所以我的X_train是(30000*6)
根据keras的说明文档,input shape应该是(samples,timesteps,input_dim)
所以我觉得我的input shape应该是:input_shape=(30000,1,6),但是运行后报错:
Input 0 is incompatible with layer lstm_6: expected ndim=3, found ndim=4

我觉得是input shape错了,改成(1,6)错误又变成了:
ValueError: Error when checking input: expected lstm_7_input to have 3 dimensions, but got array with shape (30000, 6)
改成(30000,6)错误提示一样
我该怎么设置input shape呢,多谢!

老哥,首先你需要理解为什么input_shape是三维的,以及每一个维度是什么含义。

个人粗浅理解input_shape是为了适应时间序列预测:输入m个序列,输出1个序列,所以才是三维。

input_shape的三个维度samples, time_steps, features

features: 是一个原始样本的特征维数, 对你的样本 6
time_steps: 是输入时间序列的长度,即用多少个连续样本预测一个输出。如果你希望用连续m个序列(每个序列即是一个原始样本),那么就应该设为m。
当然,特殊情况是m=1
samples:经过格式化后的样本数。假设原始样本(3000*6), 你选择features=6, time_steps=m,则samples=3000/m

无论你如何设置time_steps需要注意,原始样本集合是二维向量, 但网络的输入的样本集必须是三维张量(单个样本是二维向量)

一个例子
原始样本集 (3000, 6):
[[1,1,1,1,1,1] * 3000]
处理后(3000, 1, 6)
[
[[1,1,1,1,1,1]] * 3000
]

https://blog.csdn.net/x_ym/article/details/77728732

expected lstm_7_input to have 3 dimensions,要求的数据是三维的啊, (30000, 6),这是二维,你要对其中某一维再reshape