首页 > 解决方案 > LSTM 预测中的错误形状

问题描述

我训练了一个模型:

trainX = trainX.reshape(1, 43164, 17)
trainY = trainY.reshape(43164, 1)

model = Sequential()
model.add(LSTM(2, input_shape=(43164, 17)))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(trainX, trainY[0], epochs=100)

testX.shape # (8633, 17)
testX = testX.reshape(1, 8633, 17)

当我对这些数据进行预测时,我得到了一个错误:

Error when checking input: expected lstm_26_input to have shape (43164, 17) 
but got array with shape (8633, 17)

我该怎么做才能获得好的结果?

标签: pythonmachine-learningkerasdeep-learninglstm

解决方案


在深度学习网络的序列模型 中,您可以使用有限的短窗口以改变窗口的步幅传递数据,或者

使用一维向量传递所有序列

trainX = trainX.reshape( 43164,1, 17)
trainY = trainY.reshape(43164, 1)

model = Sequential()
model.add(LSTM(2, input_shape=(1, 17)))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(trainX, trainY[0], epochs=100)

testX.shape # (8633, 17)
testX = testX.reshape(8633,1, 17)

推荐阅读