NARX Neural Network test on new test set?

5 views (last 30 days)
After training NARX net.I want to evaluate the model on independent test set "testX'".But it returns me an error.I am testing the model by forecastLoad = sim(net, testX')'.Do we need to add delays in test set also?i don't know where i am making a mistake.
%Create training set
trainInd = data.NumDate < datenum('2008-01-01');
trainX = X(trainInd,:);
trainY = data.SYSLoad(trainInd);
% Create test set to test later
testInd = data.NumDate >= datenum('2008-01-01');
testX = X(testInd,:);
testY = data.SYSLoad(testInd);
testDates = dates(testInd);
%Neural network
X = tonndata(trainX,true,false);
T = tonndata(trainY,true,false);
% Choose a Training Function
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Nonlinear Autoregressive Network with External Input
inputDelays = 1:25;
feedbackDelays = 1:25;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn);
% Prepare the Data for Training and Simulation
[x,xi,ai,t] = preparets(net,X,{},T);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t,xi,ai);
% Test the Network
y = net(x,xi,ai);
e = gsubtract(t,y);
performance = perform(net,t,y)
% View the Network
view(net)
%%Forecast using Neural Network Model
% Once the model is built, perform a forecast on the independent test set.
load Data\testSet
forecastLoad = sim(net, testX')';
  1 Comment
Greg Heath
Greg Heath on 13 Sep 2017
Searc the NEWSGROUP and ANSWERS using
greg narxnet
Hope this helps.
Greg

Sign in to comment.

Answers (1)

Greg Heath
Greg Heath on 13 Sep 2017
Edited: Greg Heath on 29 Dec 2017
The best way to begin:
Upper case for cell variables
Lowercase for noncells
Subscript o for openloop (OL)
Subscript c for closed loop (CL)
Read X & T
Define x & t using cell2mat
Determine sizes of x and t
Use divideblock so that train, val & test
are sensibly ordered for predicting the
future using a constant timestep size.
3-color plots of x= [xtrn xval xtst] and t = ...
Use xtrn, ttrn, and nncorr to determine the
values of the significant input and output lags
Plots of autocorrt and crosscorrxt with significant
values identified with 'o'
Searching NEWSGROUP and ANSWERS using
greg narxnet
should help clear up questions.
PS: To answer your last question:
You have to use new values for Xi and Ai to continue.
Hope this clears our confusion.
Thank you for formally accepting my answer
Greg
  2 Comments
Machine Learning Enthusiast
My question was not answered clearly.The main focus was i am getting an error inline
forecastLoad = sim(net, testX')'
Greg Heath
Greg Heath on 29 Dec 2017
Edited: Greg Heath on 29 Dec 2017
See my revised answer above (You have to include new values for Xi, and Ai)

Sign in to comment.

Categories

Find more on Sequence and Numeric Feature Data Workflows 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!