2017-01-01 193 views
0

我是机器学习的新手,我试图在MATLAB上实现一个神经网络,以便预测股票市场安全性的下一个未来收盘价。收盘价。现在我迷失了,所以我正在寻找一些比我更了解神经网络的人的指导。用于时间序列预测的递归神经网络

所以为了做这个预测,我试图使用递归神经网络(RNN)。为此,我使用MATLAB的本机功能layrecnet。我用来训练RNN的投入是指定日期范围(例如2010年1月1日至2015年1月1日)的每日收盘价格,我使用的目标与投入相同,一个时间单位。

因此,举例来说,如果我们有输入:

inputSeries = [0.1 0.2 0.3 0.4 0.5 0.6 0.61 0.62] 

然后我使用的目标是:

targetSeries = [0.2 0.3 0.4 0.5 0.6 0.61 0.62 0.63] 

一切都是标准化的从0到1这个方法是有道理的我的头,因为对于输入中的给定序列,网络将具有该序列的下一个值作为目标。尽管从测试数据中获得的结果来看,网络似乎无法预测任何事情;它只是遵循在测试数据上观察到的相同模式。

我一直在寻找如何实现一个RNN来预测MATLAB的序列的下一个值,虽然没有找到任何可以指引我的正确路径。我使用的方法是完全错误的吗?我不应该为此使用简单的RNN吗?我应该使用另一种方法解决这个问题吗?

回答

0

您的方法看起来很合理,而且是的RNN适合您的数据(时间序列)。然而,由于它们具有混乱的行为,并且股市预测是其中之一(其他包括缉获预测,地震预测,飓风预测......),所以存在相对较少的难以预测的问题。所以,如果你问是因为你没有收到好的结果,请牢记这一点。由于您使用的是MATLAB,因此我建议您查看NARXNET(具有外部输入的非线性自回归神经网络,https://www.mathworks.com/help/nnet/ref/narxnet.html)。这些就像类固醇上的递归神经网络一样。您想要开始以开环形式进行训练,然后以闭环形式进行再训练。这里有一个有用的链接,讨论开放/闭环形式:
https://www.mathworks.com/matlabcentral/answers/310535-narxnet-closed-loop-vs-open-loop。希望这可以帮助。这是一些让你开始的代码。

function a = myNARXNET(in, out) 

X = tonndata(in,false,false); 
T = tonndata(out,false,false); 

trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation. 

inputDelays = 1:2; 
feedbackDelays = 1:2; 
hiddenLayerSize = [10,10,10]; 

net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn); 

net.layers{1}.transferFcn = 'radbasn'; 
net.layers{2}.transferFcn = 'tansig'; 
net.layers{3}.transferFcn = 'tansig'; 

net.inputs{1}.processFcns = {'mapminmax','mapstd'}; 
net.inputs{2}.processFcns = {'mapminmax','mapstd'}; 

[x,xi,ai,t] = preparets(net,X,{},T); 

net.trainParam.max_fail = 10; 
net.trainParam.goal = 1e-10; 

net.performParam.regularization = 0.5; 

net.trainParam.epochs = 1000; 
net.trainParam.min_grad = 1e-10; 

net.divideFcn = 'dividerand'; % Divide data randomly 
net.divideMode = 'time'; % Divide up every sample 

net.divideParam.trainRatio = 70/100; 
net.divideParam.valRatio = 15/100; 
net.divideParam.testRatio = 15/100; 

net.performFcn = 'mse'; % Mean Squared Error 

net.plotFcns = {'plotperform','plottrainstate', 'ploterrhist', ... 
    'plotregression', 'plotresponse', 'ploterrcorr', 'plotinerrcorr'}; 

% Train the Network 
[net,tr] = train(net,x,t,xi,ai); 
y = net(x,xi,ai); 
e = gsubtract(t,y); 
performance = perform(net,t,y); 

%Switch the network to closed loop form and retrain 
net = closeloop(net); 
[x,xi,ai,t] = preparets(net,X,{},T); 
[net,t] = train(net,x,t,xi,ai); 
y = net(x,xi,ai); 
a = net;  

end