理解LSTM模型的input_shape

问题描述 投票:0回答:1

我将数据库划分为 40 个滚动窗口,因此我有一个形状为

(2000000, 132)
的数据框。让我们关注第一个窗口:它有 50k 行和 132 列,所以它的形状是
(50000, 132)
。我想使用所有这些来预测以下窗口中标签的值,但我不知道
input_shape
中需要什么值。我放置
input_shape=(X_train.shape[1], 1)))
是因为我认为在每次迭代中我都有
X_train.shape[1] = 132
列和 1 个时间步,但我不确定。 (我使用从 1 到 41 的
for
循环进行每次迭代)

型号为:

model = Sequential()
model.add(LSTM(units=50, activation='sigmoid', return_sequences=True, input_shape=(X_train.shape[1], 1)))
model.add(LSTM(units=50, activation='sigmoid'))
model.add(Dense(1, activation='sigmoid'))
model.summary()
 Layer (type)                Output Shape              Param #   
=================================================================
 lstm_24 (LSTM)              (None, 132, 50)           10400     
                                                                 
 lstm_25 (LSTM)              (None, 50)                20200     
                                                                 
 dense_11 (Dense)            (None, 1)                 51        
                                                                 
=================================================================
Total params: 30,651
Trainable params: 30,651
Non-trainable params: 0
_________________________________________________________________
python keras time-series lstm
1个回答
0
投票

在 LSTM 中,input_shape 是

(batch_size, timesteps, features)

首先,您需要将

X_train
转换为 3D 张量。每个 50000x132 矩阵都是一个样本。所以,
X_train
将是
(n_samples, 50000, 132)

现在,您可以将输入形状设置为

(x_train.shape[1], x_train.shape[2])

© www.soinside.com 2019 - 2024. All rights reserved.