我的輸入是簡單地用339732行和兩列的CSV文件:錯誤模型輸入:預期lstm_1_input有3個維度,但得到了與形狀陣列(339732,29)
- 第一個是29特徵值,即X
- 第二個是一個二進制標記值,即ÿ
我想訓練上堆疊LSTM模型我的數據:
data_dim = 29
timesteps = 8
num_classes = 2
model = Sequential()
model.add(LSTM(30, return_sequences=True,
input_shape=(timesteps, data_dim))) # returns a sequence of vectors of dimension 30
model.add(LSTM(30, return_sequences=True)) # returns a sequence of vectors of dimension 30
model.add(LSTM(30)) # return a single vector of dimension 30
model.add(Dense(1, activation='softmax'))
model.compile(loss='binary_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
model.summary()
model.fit(X_train, y_train, batch_size = 400, epochs = 20, verbose = 1)
這引發錯誤:
Traceback (most recent call last): File "first_approach.py", line 80, in model.fit(X_train, y_train, batch_size = 400, epochs = 20, verbose = 1)
ValueError: Error when checking model input: expected lstm_1_input to have 3 dimensions, but got array with shape (339732, 29)
我嘗試使用X_train.reshape((1,339732, 29))
重塑我的輸入,但沒有奏效示值誤差:
ValueError: Error when checking model input: expected lstm_1_input to have shape (None, 8, 29) but got array with shape (1, 339732, 29)
我怎麼能養活我輸入LSTM?