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

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

问题描述

我只是从 kaggle 均方误差为 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天全站免登陆