How to divide the data using "divideblock" for training and testing , excluding validation dataset in NAR network for time series prediction.
2 views (last 30 days)
Show older comments
I am using NAR network for time series prediction. I have to divide my datset of 133 time points into training and tetsing dataset uisng "divideblock". I want first 106 points for training and the rest for testing. I am getting the error "Attempted to access valInd(0); index must be a positive integer or logical.
Error in divideblock>divide_indices testInd = (1:numTest)+valInd(end);
Error in divideblock [out1,out2,out3] = divide_indices(in1,params);".
Here is my code:
targetSeries = tonndata(untitled,false,false);
feedbackDelays = 1:1; hiddenLayerSize = 10; net = narnet(feedbackDelays,hiddenLayerSize);
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'}; [inputs,inputStates,layerStates,targets] = preparets(net,{},{},targetSeries);
net.divideFcn = 'divideblock'; [trainInd,valInd,testInd] = divideblock(133,0.8,0,0.2)
net.divideMode = 'time'; % Divide up every value net.divideParam.trainRatio = 80/100; net.divideParam.valRatio = 0/100; net.divideParam.testRatio = 20/100;
net.trainFcn = 'trainlm'; % Levenberg-Marquardt
net.performFcn = 'mse'; % Mean squared error
net.plotFcns = {'plotperform','plottrainstate','plotresponse','ploterrcorr', 'plotinerrcorr'};
[net,tr] = train(net,inputs,targets,inputStates,layerStates);
outputs = net(inputs,inputStates,layerStates);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs)
trainTargets = gmultiply(targets,tr.trainMask);
valTargets = gmultiply(targets,tr.valMask);
testTargets = gmultiply(targets,tr.testMask);
trainPerformance = perform(net,trainTargets,outputs)
valPerformance = perform(net,valTargets,outputs)
testPerformance = perform(net,testTargets,outputs)
view(net)
netc = closeloop(net); [xc,xic,aic,tc] = preparets(netc,{},{},targetSeries); yc = netc(xc,xic,aic); perfc = perform(net,tc,yc)
nets = removedelay(net);
[xs,xis,ais,ts] = preparets(nets,{},{},targetSeries);
ys = nets(xs,xis,ais);
closedLoopPerformance = perform(net,tc,yc)
0 Comments
Answers (1)
Kazi Tamaddun
on 17 May 2018
Edited: Kazi Tamaddun
on 17 May 2018
Your valRatio cannot be zero. You can make your testRatio to be zero if you want.
0 Comments
See Also
Categories
Find more on Signal Modeling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!