时间序列预测的递归神经网络

时间:2017-01-01 21:17:05

标签: matlab machine-learning neural-network

我是机器学习的新手,我试图在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吗?我应该使用另一种方法解决这个问题吗?

1 个答案:

答案 0 :(得分: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