这可以正确预测喀拉拉邦的下一个价值吗? [英] is this correctly work on predict next value in keras?
问题描述
这是我的代码
...
look_back = 20
train_size = int(len(data) * 0.80)
test_size = len(data) - train_size
train = data[0:train_size]
test = data[train_size:len(data)]
x_train, y_train = create_dataset(train, look_back)
x_test, y_test = create_dataset(test, look_back)
x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1], 1))
x_test = np.reshape(x_test, (x_test.shape[0], x_test.shape[1], 1))
y_train=np.repeat(y_train.reshape(-1,1), 20, axis=1).reshape(-1,20,1)
y_test=np.repeat(y_test.reshape(-1,1), 20, axis=1).reshape(-1,20,1)
...
model = Sequential()
model.add(LSTM(512, return_sequences=True))
model.add(Dropout(0.3))
model.add(LSTM(512, return_sequences=True))
model.add(Dropout(0.3))
model.add(LSTM(1, return_sequences=True))
model.compile(loss='mean_squared_error', optimizer='rmsprop', metrics=['accuracy'])
model.summary()
model.fit(x_train, y_train, epochs=10, batch_size=64)
p = model.predict(x_test)
,我想预测下一个值,所以,
predictions = model.predict(x_train)
,形状为(62796, 20, 1)
and I want to predict the next value So,
predictions = model.predict(x_train)
and shape is (62796, 20, 1)
and I coded the following site how to use the Keras model to forecast for future dates or events?
future = []
currentStep = predictions[-20:, :, :] # -20 is last look_back number
for i in range(10):
currentStep = model.predict(currentStep)
future.append(currentStep)
在此代码中,将来的结果是
in this code future's result is
但是p = model.predict(x_test)
的[:4000]结果是
but p = model.predict(x_test)
's [:4000] result is
两个结果之间的差异非常大.
The difference between the two results is very large.
这是预测下一个值的正确方法吗?
is this right way to Predict the next value??
我不知道哪里出错或代码出错.
I don't know where it went wrong or the code went wrong.
希望您能提出意见.
完整的源代码是 https://gist.github.com/Lay4U/654f70bd1fb9c4f7d5bdb21adcbb> /p>
full source is https://gist.github.com/Lay4U/654f70bd1fb9c4f7d5bdb21ddcb588ab
推荐答案
根据您的代码,您尝试使用lstm预测下一个值. 因此,在这里您必须正确地重塑输入数据以反映时间步长和功能.
According to your code you are trying to predict next value using lstm. So here you have to reshape your input data correctly to reflect the time steps and features.
model.add(LSTM(512, return_sequences=True))
您不必编写此代码:
model.add(LSTM(512, input_shape=(look_back,x)))
x =训练数据中的输入要素.
x = input features in your training data.
我想本文将有助于简化您的代码并预测未来的价值:
I guess this article will help to moderate your code and predict the future value:
本文将帮助您更多地了解如何预测未来价值:
This article will help you to understand more about how to predict future value:
谢谢
这篇关于这可以正确预测喀拉拉邦的下一个价值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!