小编Deu*_*eus的帖子

检查目标时出错:预期density_1具有3维,但数组的形状为(118,1)

我正在训练一个模型来预测股票价格,而输入数据是收盘价。我使用45天的数据来预测第46天的收盘价,而经济指标将成为第二个特征,这是模型:

model = Sequential()
model.add( LSTM( 512, input_shape=(45, 2), return_sequences=True))
model.add( LSTM( 512, return_sequences=True))
model.add( (Dense(1)))
model.compile(loss='mse', optimizer='adam')
history = model.fit( X_train, y_train, batch_size = batchSize, epochs=epochs, shuffle = False)
Run Code Online (Sandbox Code Playgroud)

运行此命令时,出现以下错误:

ValueError:检查目标时出错:预期density_1具有3维,但数组的形状为(118,1)

但是,我print的数据形状是:

X_train:(118, 45, 2)
y_train:(118, 1)
Run Code Online (Sandbox Code Playgroud)

我不知道为什么当y_train为(118,1)时模型期望3维输出。我在哪里错了,该怎么办?

python output lstm keras

10
推荐指数
2
解决办法
1万
查看次数

标签 统计

keras ×1

lstm ×1

output ×1

python ×1