简体   繁体   中英

What values should I take of input_shape of LSTM in below model

这些是代码LSTM模型的图像,请帮助我为第一个LSTM层提供适当的input_dim值

For the code you gave, all possible answers are wrong.

A LSTM layer accepts a 3D input tensor of shape (batch_dim, time_dim, feat_dim) , and you should write input_shape=(time_dim, feat_dim) in the layer definition.

However, since you use X_train = np.expand_dims(X_train, axis=0) , it implies there is only one training sample in your data, which completely makes no sense. I therefore suspect what you really want to do is

X_train = np.expand_dims(X_train, axis=-1)

which has X_train.shape[0] of samples, X_train.shape[1] of time steps, and only 1 feature dimension, which is sort of common in many time-series analysis problem.

If my guess is correct, then your input shape of LSTM should be of shape (X_train.shape[1], 1) .

NOTE: the batch_dim is intentionally not specified by keras's setting, which makes sense, because if you include it in your model definition, then you have to use to this particular batch size for both training and testing, while this is very inconvenient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM