[英]Feeding input into keras Sequential model
我正在與Keras進行時間序列預測。 我的輸入數據中有10個時間步長,其形狀為(2688, 10, 1)
2688,10,1 (2688, 10, 1)
即train_x.shape和train_y.shape為(2688,10,1)。 嘗試將其輸入模型時出現以下錯誤。
ValueError: Error when checking target: expected activation_1 to have 2 dimensions, but got array with shape (2688, 10, 1)
我提供給第一lstm層的輸入形狀: input_shape=(1, time_steps)
**
我可以正確地重塑train_y嗎?
**
time_steps=10
train_x = np.reshape(train_x, (train_x.shape[0], train_x.shape[1], 1))
train_y = np.reshape(train_y, (train_y.shape[0], train_y.shape[1], 1))
# lstm model
model = Sequential()
model.add(LSTM(128, input_shape=(time_steps, 1), return_sequences=True))
model.add(LSTM(64))
model.add(Dense(1))
model.add(Activation('linear'))
model.compile(loss='mse', optimizer='adam')
history = model.fit(train_x, train_y, epochs=10, validation_data=(test_x,
test_y), batch_size=64, verbose=1)
如果您期望形狀(2688、10、1),則不能輸入_shape =(1,time_steps)。 它應該input_shape =(time_steps,1)
train_x = np.reshape(train_x, (train_x.shape[0], train_x.shape[1], 1))
train_y = np.reshape(train_y, (train_y.shape[0], train_y.shape[1], 1)
我認為錯誤在這里,您應該給定shape [0]和shape [1]之間的時間步長。
train_x = np.reshape(train_x, (train_x.shape[0], 10,train_x.shape[1]))
train_y = np.reshape(train_y, (train_y.shape[0],10, train_y.shape[1]))
這里的值“ 10”表示時間步長!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.