[英]Why does model.predict give 3 outputs?
I'm trying to use Keras to make predictions on a univariate time series.我正在尝试使用 Keras 对单变量时间序列进行预测。
The NN model looks like NN model 看起来像
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d (Conv1D) (None, None, 25) 150
_________________________________________________________________
lstm (LSTM) (None, None, 1024) 4300800
_________________________________________________________________
dropout (Dropout) (None, None, 1024) 0
_________________________________________________________________
lstm_1 (LSTM) (None, None, 1024) 8392704
_________________________________________________________________
dropout_1 (Dropout) (None, None, 1024) 0
_________________________________________________________________
lstm_2 (LSTM) (None, None, 1024) 8392704
_________________________________________________________________
dropout_2 (Dropout) (None, None, 1024) 0
_________________________________________________________________
lstm_3 (LSTM) (None, None, 1024) 8392704
_________________________________________________________________
dropout_3 (Dropout) (None, None, 1024) 0
_________________________________________________________________
dense (Dense) (None, None, 1) 1025
=================================================================
Total params: 29,480,087
Trainable params: 29,480,087
Non-trainable params: 0
_________________________________________________________________
My data is windowed using the previous 3 values of the series to predict the next.我的数据使用该系列的前 3 个值进行窗口化,以预测下一个。 Thus my test dataset looks like因此我的测试数据集看起来像
list(dataset.as_numpy_iterator())
[array([[[ 0. ],
[ 0.02346429],
[ 0.04559132]],
[[ 0. ],
[ 0.02161974],
[ 0.13014923]],
[[ 0. ],
[ 0.10623277],
[-0.02918068]],
[[ 0. ],
[-0.12240955],
[-0.21869095]]])]
All well and good, but when I feed this to model.predict(dataset)
the output it spits out is一切都很好,但是当我把它model.predict(dataset)
时,它吐出的 output 是
array([[[ 0.01316399],
[ 0.03728709],
[ 0.06164959]],
[[ 0.01316399],
[ 0.03512047],
[ 0.1292857 ]],
[[ 0.01316399],
[ 0.1172413 ],
[-0.01671433]],
[[ 0.01316399],
[-0.10654409],
[-0.16395506]]], dtype=float32)
and the shape for this example is (4, 3, 1)
这个例子的形状是(4, 3, 1)
I was expecting just to get a single predict for each triplet of input features, given the final layer of my NN is a Dense with a single unit.考虑到我的 NN 的最后一层是具有单个单元的 Dense,我期望只为每个三元组输入特征获得一个预测。 Why do I seem to have three outputs in the prediction for each training example?为什么每个训练示例的预测中似乎都有三个输出?
In your last LSTM layer, set the argument return_sequences=False.在最后一个 LSTM 层中,设置参数 return_sequences=False。
LSTM(..., return_sequences=False)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.