股票预测:GRU模型预测相同的给定值,而不是未来的股票价格 [英] stock prediction : GRU model predicting same given values instead of future stock price

查看:925
本文介绍了股票预测:GRU模型预测相同的给定值,而不是未来的股票价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从kaggle进行了此模型的测试发布 该模型假设将从给定的最后一批库存中提前1天进行预测.如您所见,在调整了几个参数后,我获得了令人惊讶的好结果. 均方误差为5.193.所以总体而言,它看起来很好地预测了未来的股票吧?好吧,当我仔细观察结果时,结果真是太恐怖了.

i was just testing this model from kaggle post this model suppose to predict 1 day ahead from given set of last stocks. After tweaking few parameters i got surprisingly good result, as you can see. mean squared error was 5.193.so overall it looks good at predicting future stocks right? well it turned out to be horrible when i take a look closely on the results.

如您所见,该模型正在预测给定库存的最后价值,即我们当前的最后库存.
所以我确实将预测调整了一步. 因此,您现在可以清楚地看到该模型正在预测倒退或最后一个股票奖励,而不是将来的股票预测.

as you can see that this model is predicting last value of the given stocks which is our current last stock.
so i did adjusted predictions to one step back.. so now you can clearly see that model is predicting one step backward or last stock prise instead of future stock predictions.

# So for each element of training set, we have 30 previous training set elements 
X_train = []
y_train = []

previous = 30

for i in range(previous,len(training_set_scaled)):
    X_train.append(training_set_scaled[i-previous:i,0])
    y_train.append(training_set_scaled[i,0])
X_train, y_train = np.array(X_train), np.array(y_train)


print(X_train[-1],y_train[-1])

这是我的模特

# The GRU architecture
regressorGRU = Sequential()
# First GRU layer with Dropout regularisation
regressorGRU.add(GRU(units=50, return_sequences=True, input_shape=(X_train.shape[1],1)))
regressorGRU.add(Dropout(0.2))
# Second GRU layer
regressorGRU.add(GRU(units=50, return_sequences=True))
regressorGRU.add(Dropout(0.2))
# Third GRU layer
regressorGRU.add(GRU(units=50, return_sequences=True))
regressorGRU.add(Dropout(0.2))
# Fourth GRU layer
regressorGRU.add(GRU(units=50))
regressorGRU.add(Dropout(0.2))
# The output layer
regressorGRU.add(Dense(units=1))

# Compiling the RNN
regressorGRU.compile(optimizer='adam',loss='mean_squared_error')
# Fitting to the training set
regressorGRU.fit(X_train,y_train,epochs=50,batch_size=32)

此处是我的完整代码,您也可以在google colab上运行此代码.

And here is my full code, you also able to run this code at google colab.

所以我的问题是背后的原因是什么?我在做什么错什么建议?

so my question is what is the reason behind it? what am i doing wrong any suggestions?

推荐答案

实际上这是一个众所周知的回归问题.由于回归器的任务是最大程度地减少错误,因此可以通过从输入到回归器的要素中选择最接近的值来确保任务的安全.尤其是在时间序列问题中.

It is a well-known issue with regression actually. Since the task of the regressor is to minimize error, it secures it task by choosing the closest value from the features you input to the regressor. It becomes the case especially in the time-series problems.

1)切勿提供您希望模型预测的未处理的结束值,尤其是在时间序列回归问题中.更笼统地说,永远不要提供给回归器一些直接数字直觉的功能,以告知标签可能是什么.

1) Never give unprocessed closing value that you want your model to predict, especially in the time-series regression problems. More generally, never give a feature that gives some direct numerical intuition to a regressor about what the label might be.

2)如果不确定模型是否像您的案例一样复制,请确保将原始测试集和预测一起绘制以直观地分析情况.此外,如果可以的话,请根据实时数据对模型进行仿真,以观察模型是否具有相同的预测性能.

2)If you are not sure whether the model just replicates like your case, be sure to plot the original test set and your prediction all together to visually analize the situation. Moreover, if you can, do a simulation of your model on the real-time data to observe whether your model predicts with the same performance.

3)我建议您应用二进制分类而不是回归.

3)I’d recommend you to apply binary classification rather than regression.

近一年来我一直在努力进行财务信号预测,请随时提出更多要求.

I’ve been intensely working on financial signal prediction for nearly a year, do not hesitate to ask more.

玩得开心.

这篇关于股票预测:GRU模型预测相同的给定值,而不是未来的股票价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆