python - 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)
我该怎么做才能获得好的结果?
解决方案
在深度学习网络的序列模型 中,您可以使用有限的短窗口以改变窗口的步幅传递数据,或者
使用一维向量传递所有序列
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)
推荐阅读
- php - Laravel Nova 管理面板的多语言变量
- amazon-web-services - 如何将具有自定义域名的 API Gateway 迁移到另一个 AWS 账户?
- c# - WPF 从具有双向绑定的 ViewModel 中选择 DataGrid 中的多个项目
- mysql - mysql 表很少,一个大表上的子查询执行缓慢
- firebase - firebase 中的 queryReference 和 querySnapshot 有什么区别?
- azure-active-directory - Android MSAL 配置和授权 URL
- visual-studio-code - VS Code 使用了错误的 Python 解释器
- r - 如果值出现在特定行中,则返回 3 下一行和上一行
- google-cloud-platform - 根据 GCP Cloud SQL 日志创建报告
- python - BertForTokenClassification 未加载