如何为LSTM模型创建输出图层?

时间:2019-12-01 07:04:14

标签: python tensorflow lstm

我还在学习LSTM分类。

my input dataset is (2386, 3) where (n_rows, n_predictive)
my output dataset is (2386, 7) where (n_rows, n_label)

my input windows size is (2369, 12, 3) where (n_sample, n_input, n_predictive)
my output windows size is (2369, 6, 7) where (n_sample, n_output, n_label)

using this code
        model = Sequential()
        model.add(LSTM(300, return_sequences=True, input_shape=(n_input, n_predictive)))
        model.add(TimeDistributed(Dense(n_label)))
        model.add(Activation('softmax'))
        model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['acc'])

obtain this layer
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
cu_dnnlstm_93 (CuDNNLSTM)    (None, 12, 300)           363600    
_________________________________________________________________
time_distributed_14 (TimeDis (None, 12, 7)             2107      
_________________________________________________________________
activation_13 (Activation)   (None, 12, 7)             0         
=================================================================

及其错误

 Error when checking target: expected activation_13 to have shape (12, 7) but got array with shape (6, 7)

我尝试创建图层,但是我无法使用(None,6,7)创建图层,你们对我如何使用(None,6)创建图层有任何建议,7)?

更新

当我尝试使用相同的输入和输出窗口来拟合模型时,如下所示

input windows size is (2369, 12, 3)
output windows size is (2369, 12, 7)

该模型没有错误,但我发现标签预测比实际延迟了12步。

例如,当我使用不同的窗口大小时

input windows size is (2369, 6, 3)
output windows size is (2369, 6, 7)

我发现标签预测比实际预测晚了6步。

我已经检查了Windows拆分序列功能,在这里我遵循此博客https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/的代码

窗口拆分工作正常。但是似乎LSTM模型工作异常。 LSTM分类模型是否会受到窗口大小的影响?

0 个答案:

没有答案