小编Car*_*oen的帖子

LSTM Keras网络的恒定输出和预测语法

我是神经网络的新手,有两个,可能是非常基本的问题.我正在建立一个通用的LSTM网络,以根据多个功能预测序列的未来.因此,我的训练数据具有形状(训练序列的数量,每个序列的长度,每个时间步长的特征量).或者使它更具体,类似于(2000,10,3).我试图预测一个特征的价值,而不是所有三个特征的价值.

  1. 问题:

如果我使我的网络更深和/或更宽,我得到的唯一输出是要预测的值的常数平均值.以此设置为例:

z0 = Input(shape=[None, len(dataset[0])])

z = LSTM(32, return_sequences=True, activation='softsign', recurrent_activation='softsign')(z0)
z = LSTM(32, return_sequences=True, activation='softsign', recurrent_activation='softsign')(z)
z = LSTM(64, return_sequences=True, activation='softsign', recurrent_activation='softsign')(z)
z = LSTM(64, return_sequences=True, activation='softsign', recurrent_activation='softsign')(z)
z = LSTM(128, activation='softsign', recurrent_activation='softsign')(z)

z = Dense(1)(z)
model = Model(inputs=z0, outputs=z)
print(model.summary())

model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy'])

history= model.fit(trainX, trainY,validation_split=0.1, epochs=200, batch_size=32, 
    callbacks=[ReduceLROnPlateau(factor=0.67, patience=3, verbose=1, min_lr=1E-5),
            EarlyStopping(patience=50, verbose=1)])
Run Code Online (Sandbox Code Playgroud)

这就是像这样的网络的结果. 注意:这些是用于培训的输入的预测

如果我只使用一层,如:

z0 = Input(shape=[None, len(dataset[0])])

z = LSTM(4, activation='soft sign', recurrent_activation='softsign')(z0)

z = Dense(1)(z)
model = Model(inputs=z0, outputs=z)
print(model.summary())

model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy']) …
Run Code Online (Sandbox Code Playgroud)

python neural-network lstm keras tensorflow

5
推荐指数
1
解决办法
1016
查看次数

标签 统计

keras ×1

lstm ×1

neural-network ×1

python ×1

tensorflow ×1