在使用TensorFlow进行Sequential预测时需要更高的准确性

使用的编程语言是Python 3系列,并使用了TensorFlow。

这是我编写的代码。

from keras.models import Sequentialfrom keras.layers import Densefrom sklearn.datasets import make_regressionfrom sklearn.preprocessing import MinMaxScalerfrom numpy import arrayimport numpy as npimport randomxx1 = 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 answerXnew = array([[15, 8, 3]])##predicted value : 15*8+3+5 = 128# make a predictionynew = model.predict(Xnew)# show the inputs and predicted outputsprint("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 + 5的结果,但实际上与此相差甚远,具体来说,超过10000。我希望能更准确地预测这个输出,但我不知道该怎么做。我该怎么办?


回答:

如果你试图构建一个用于序列预测的模型,可以使用循环神经网络。因为你在使用Keras,可以添加一些LSTM或GRU层以获得更好的结果。你可以在下面的链接中了解更多关于这些层的 информация。

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

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注