How to perdict timeseries using already trained net from nnstart tool in Matlab
6 views (last 30 days)
Show older comments
Muhammad Usman Saleem
on 13 May 2023
Commented: Muhammad Usman Saleem
on 15 May 2023
Through google I find nnstart tool where I can predict my timeseries dataset, I opened this app and seletec NAR option then select target as martrix column, then after partition my data I used Levenberg-Marquardt as training algothim. After getting best training and validation results I save the model output in my workspace. I want to predict from this train net 5 years ahead of my timeseries data in data variable however whenever I run predict or predictAndUpdate my code below error:
>> predict(net,data)
Error using predict (line 126)
No valid system or dataset was specified.
>> predictAndUpdateState(net,data)
Undefined function 'predictAndUpdateState' for input arguments of type 'network'.
I've called my timeseries data from excel file to matrix data (1,20 size) and want to get predicted data(1,25 size) using this tool. I am also sharing my workspace variables contain input variable data and output variables from train model using nntool (error,info,net,output, results) please guide me how can I predict my data variable 5 steps ahead using this train network? Many thanks for timely reply please
0 Comments
Accepted Answer
LeoAiE
on 13 May 2023
here is what I did:
% Load data
load('Test_1.mat');
dataSeries = data;
% Prepare input and target data
X = num2cell(dataSeries, 1);
T = X;
% Define and train the NARX network
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 10;
net = narxnet(inputDelays, feedbackDelays, hiddenLayerSize);
% Divide data into training, validation, and testing sets
net.divideFcn = 'divideblock';
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Prepare the data for training
[xs, xi, ai, ts] = preparets(net, X, {}, T);
% Train the NARX network
[net, tr] = train(net, xs, ts);
% Make predictions
nPredict = 5; % Number of steps ahead to predict
netc = closeloop(net);
[xc, xi, ai, tc] = preparets(netc, X, {}, T);
YPredicted = netc(xc, xi, ai);
% Convert the predicted output back to a matrix format
YPredictedMatrix = cell2mat(YPredicted);
% Transpose the YPredictedMatrix
YPredictedMatrix = YPredictedMatrix';
% Create a new variable to store the original data and the predicted values
6 Comments
More Answers (0)
See Also
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!