I have constructed my neural network, how can I now use it to predict?

2 views (last 30 days)
Hi, I am building an MLP NN to predict the closing price. The data consists of daily open, close, high and low for the period 1/09/03 - 12/29/17. The training is standard 70% 15% testing 15% validating, whereby the data for the training is all the inputs from 1/09/03 - 1/08/15. The target is the closing price from 2/09/15 - 1/09/15. I want to predict the remaining period from 1/12/15 - 12/29/17 and plot the predicted vs the actual. Also, I am missing many steps can you please assist? I will now present the code for building the network;
[input,PS] = mapminmax(inputs);
[target,TS] = mapminmax(targets);
net = feedforwardnet(20,'trainlm');
net = configure(net,input,target); view(net)
net = init(net);
[net,tr] = train(net,input,target); view(net)
Can you please help me predict and plot, any information will be greatly appreciated.

Answers (2)

Vishal Chaudhary
Vishal Chaudhary on 13 Aug 2018
For predicting you can use following :
y = net(x); % x contains input data and y is predicted data
If you want to create plot of prediction you can use plot command.
For general NN code see following:
x = input;
t = target;
trainFcn = 'trainlm';
hiddenLayerSize = [10 15 10]; % 3hiddenlayers of with different no. of neurons
net = feedforwardnet(hiddenLayerSize,trainFcn);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
view(net)
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t)

Saad Ibrahim
Saad Ibrahim on 13 Aug 2018
Hi Vishal,
Thank you for your reply. I have made the necessary updates but once I have predicted using your code y = net(x), how can I compare with the actual from the holdout sample? Additionally, how do I partition the data? As currently, I can't see how it's using the data from 1/09/03 - 1/08/15 for training and 1/12/15 - 12/29/17 for testing.
Regards
  1 Comment
Vishal Chaudhary
Vishal Chaudhary on 13 Aug 2018
For partitioning into train,test,validation I have already mentioned code. If by comparing with actual you mean actual closing price then compute the type of loss you think would be good or visualize it by plotting in same figure.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!