MATLAB: How to improve results for river_dataset predicting ahead

river predicting

Hi everyone, I am a begginer in using matlab neural networks. It would be great if someone could help me to obtain better results. This is my code. Thanks!
%%1. Importing data
load('river_dataset')
T=riverTargets;
%%2. Data preparation
N = 12; % Multi-step ahead prediction
% Input and target series are divided in two groups of data:
% 1st group: used to train the network
targetSeries = T(1:end-N);
% 2nd group: this is the new data used for simulation. inputSeriesVal will
% be used for predicting new targets. targetSeriesVal will be used for
% network validation after prediction
targetSeriesVal = T(end-N+1:end); % This is generally not available
%%3. Network Architecture
delay = 2;
neuronsHiddenLayer = 10;
% Network Creation
net = narnet(1:delay,neuronsHiddenLayer);
%%4. Training the network
[Xs,Xi,Ai,Ts] = preparets(net,{},{},targetSeries);
net = train(net,Xs,Ts,Xi,Ai);
view(net)
Y = net(Xs,Xi,Ai);
% Performance for the series-parallel implementation, only
% one-step-ahead prediction
perf = perform(net,Ts,Y);
%%5. Multi-step ahead prediction
targetSeriesPred = [targetSeries(end-delay+1:end), con2seq(nan(1,N))];
netc = closeloop(net);
view(netc)
[Xs,Xi,Ai,Ts] = preparets(netc,{},{},targetSeriesPred);
yPred = netc(Xs,Xi,Ai);
perf = perform(net,yPred,targetSeriesVal);
figure;
plot([cell2mat(targetSeries),nan(1,N);
nan(1,length(targetSeries)),cell2mat(yPred);
nan(1,length(targetSeries)),cell2mat(targetSeriesVal)]')
legend('Original Targets','Network Predictions','Expected Outputs')

Best Answer

You are misusing the term validation.
total = design + test
design = training + validation
The validation set is part of the design set and helps determine when to stop training. Estimates of performance on nondesign data (i.e., generalization) are obtained using a "holdout" test set.
Apply your data to the help example
help narnet
Use divideblock to create the training, validation and test sets with uniform spacing.
Later you can see what happens if you try to exclude the validation set.
Initialize the RNG and obtain the training record tr:
rng(0)
[ net tr Ys Es Xf Af ] = train(net,Xs,Ts,Xi,Ai);
Search for some of my posts
greg narnet
Thank you for formally accepting my answer
Greg