使用张量流时需要更高的准确性,顺序预测

need more accuracy while using tensorflow, Sequential predicting

语言是 Python 3 系列。 使用 Tensorflow。

这是我编写的代码。

from keras.models import Sequential
from keras.layers import Dense
from sklearn.datasets import make_regression
from sklearn.preprocessing import MinMaxScaler
from numpy import array
import numpy as np
import random

xx1 = array(random.sample(range(0,1000), 1000))
xx2 = array(random.sample(range(0,2000), 1000))
xx3 = array(random.sample(range(0,4000), 1000))

xx = np.dstack((xx1, xx2, xx3))


yy = np.array(xx1*xx2+xx3 +5)


model = Sequential()
model.add(Dense(4, input_dim=3, activation='relu'))
model.add(Dense(4, activation='relu'))
model.add(Dense(1, activation='linear'))
model.compile(loss='mse', optimizer='adam')
model.fit(xx[0], yy, epochs=1000, verbose=0)
## xx[0] : 1000*3 input dataset, yy : 1000*1 output dataset
# new instance where we do not know the answer
Xnew = array([[15, 8, 3]])
##predicted value : 15*8+3+5 = 128
# make a prediction
ynew = model.predict(Xnew)
# show the inputs and predicted outputs

print("xx[0] : %s" % (xx[0]))
print("yy : %s" % (yy))
print("XinPut=%s, Predicted=%s" % (Xnew[0], ynew[0]))

我制作了这段代码。 xx[0] 是 1000 * 3 输入数据集。 yy 是 1000 * 1 输出数据集。

我把yy设为xx1 * xx2 + xx3 + 5,xx1是xx[0,0],xx2是xx[0,1],xx3是xx[0,2]

我想预测 [15, 8, 3] 的输出。 正如我所想,它应该接近 128,即 15 * 8 + 3 的结果,但实际上,它远非如此。正好,超过10000。 我想让这个输出更准确,但不知道怎么做。 我该怎么办?

如果您尝试构建模型来预测系列,请为此使用递归神经网络。由于您使用的是 Keras,因此添加一些 LSTM 或 GRU 层以获得更好的结果。您可以在下面阅读有关这些层的更多信息 link

https://keras.io/layers/recurrent/#rnn