python - LSTM 预测时形状错误

标签 python machine-learning keras deep-learning 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)

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

最佳答案

Sequential modesls在深度学习网络中,您可以通过改变窗口的步幅以有限的短窗口传递数据,或者

用一维向量传递所有序列

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)

关于python - LSTM 预测时形状错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54576155/

相关文章:

machine-learning - Caffe 只训练一个标签

python - 用于训练/验证/测试集拆分的 SHA 哈希

python - Keras 模型通过编译但在运行时因值错误而崩溃

tensorflow - 使用convert_variables_to_constants保存tf.trainable_variables()

python - 使用 python 从 .txt 文件检索数据?

python - 具有特殊规则的 Pandas agg 数组

python-3.x - (无法将字符串转换为 float )使用 knn 算法时出错

python - 无法在 Python TensorFlow 中用 LSTMBlockFusedCell 替换 LSTMBlockCell

c++ - Boost.Python - 将 boost::python::object 作为参数传递给 python 函数?

python - 如何根据keras中的条件替换张量的某些部分?