Keras 1.2.2和Keras 2.2预测的差异

时间:2018-07-06 13:44:46

标签: python tensorflow machine-learning keras lstm

我试图用LSTM神经网络预测正弦曲线。我花了一些时间,但我无法真正获得好的预测结果。经过一些值后,正弦曲线总是变得混乱。所以我从这篇文章中得到了一些启发:

http://www.jakob-aungiers.com/articles/a/LSTM-Neural-Network-for-Time-Series-Prediction

即使根据先前的预测进行预测,他的正弦曲线也只有一点偏移。所以我复制了他的确切代码,但得到了这个预测: enter image description here

代替他: enter image description here

一段时间后,我意识到他使用了:

TensorFlow 1.0
Keras 1.2.2

所以我安装了Keras 1.2.2来检查它和tensorflow版本1.2.0是否有所不同,因为Windows上没有早期版本。然后我得到了这个预测: enter image description here

您可以看到正弦曲线更精确,因为它在[-1,1]的值范围内,但比他的预测要偏移得多。

我已经尝试了多次,结果非常相似。当Keras 1.2保持在其值范围内时,一段时间后Keras 2.2的预测幅度总是变小。但是我从来没有像他这样的好预测。

我需要更多培训吗?我已经使用了20个纪元,批量大小为512个。 我如何得到这样的预测? 较新的Keras版本会给出更谨慎的预测吗?

这是我使用的模型:

def build_model(layers):
    model = Sequential()

    model.add(LSTM(
        input_shape=(None, layers[0]),
        #units=layers[1],
        output_dim=layers[1],
        return_sequences=True))
    model.add(Dropout(0.2))

    model.add(LSTM(
        layers[2],
        return_sequences=False))
    model.add(Dropout(0.2))

    model.add(Dense(
        output_dim=layers[3]))
    model.add(Activation("linear"))

    start = time.time()
    model.compile(loss="mse", optimizer="rmsprop")
    print("> Compilation Time : ", time.time() - start)
    return model

具有以下参数:

model = build_model([1, 50, 100, 1])

完整代码可在此处找到

https://github.com/VictorW96/sinprediction

0 个答案:

没有答案