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

2024-06-16 08:57:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我还在学习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 split sequence函数,在这里我从这个blog https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/中看到了这些代码

窗户裂开的很好。但似乎LSTM模型工作起来很奇怪。分类的LSTM模型是否受窗口大小的影响


Tags: 模型noneaddinputoutputsizemodelis