How to create Prediction file in nnstart similar to nntool?

42 views (last 30 days)
Hi dears
I started with "nntool" and happily introduced my test sample (as input) and generate my prediction (as an output file- not known initially). I start learning "nnstart" and like all wonderfull plots but I cannot self define the output. The app requires the sample and the prediction simultaneously!
How can I use like "nntool" for "nnstart" by giving only sample and ask the trained model to predict and store the output in my desirable filename?
Thanks for you help me out.

Answers (2)

Ronit
Ronit on 28 Mar 2024
Hi Ahmad,
The ‘nntool’ interface is no longer supported and has been deprecated. The recommended alternative now is to use nnstart.
You have previously enjoyed using nntool for inputting a sample and obtaining a prediction without the need to specify the actual output, I've found a workaround using MATLAB scripting. This method is designed to replicate that process as closely as possible, assuming you have a trained model ready.
Start by launching the ‘nnstart’ GUI. You can do this by typing nnstart in the MATLAB command window.
Create and Train the network by following the prompts in ‘nnstart’ to create and train your neural network. This will involve selecting the type of network, configuring its parameters, and training it using your dataset. You'll need to have both inputs and targets available for this step, as ‘nnstart’ is designed to guide you through the training process.
After training and exporting your network using ‘nnstart’, switch to scripting to make predictions using only your input samples.
  1. Load your trained network.
  2. Prepare your sample input.
  3. Predict using the trained network.
  4. Save the prediction to a desired file.
load('trainedNetwork.mat'); % Use your filename
inputSample = ['/input comes here'/];
outputPrediction = predict(trainedNetwork, inputSample);
desiredFilename = 'predictionOutput.mat';
save(desiredFilename, 'outputPrediction');
If you need further customization or assistance with specific commands or steps, please refer to the following MATLAB documentation link:
Hope this helps!
  2 Comments
Ahmad Sedaghat
Ahmad Sedaghat on 29 Mar 2024 at 22:03
Thank you for your time. I am using R2020b. After training I get
Then I get this
unclear what to do to relate to your guidlines.
Ronit
Ronit on 2 Apr 2024 at 4:13
You can go ahead and save the MATLAB scripts and perform operations on that as it is recommended.

Sign in to comment.


Ahmad Sedaghat
Ahmad Sedaghat on 30 Mar 2024 at 18:50
I get either a function or a script. For script I get the following. How to use it for a sample for my prediction?
% Solve an Autoregression Problem with External Input with a NARX Neural Network
% Script generated by Neural Time Series app
% Created 30-Mar-2024 00:35:10
%
% This script assumes these variables are defined:
%
% Train - input time series.
% Predict - feedback time series.
X = tonndata(Train,false,false);
T = tonndata(Predict,false,false);
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Nonlinear Autoregressive Network with External Input
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn);
% Prepare the Data for Training and Simulation
% The function PREPARETS prepares timeseries data for a particular network,
% shifting time by the minimum amount to fill input states and layer
% states. Using PREPARETS allows you to keep your original time series data
% unchanged, while easily customizing it for networks with differing
% numbers of delays, with open loop or closed loop feedback modes.
[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)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotresponse(t,y)
%figure, ploterrcorr(e)
%figure, plotinerrcorr(x,e)
% Closed Loop Network
% Use this network to do multi-step prediction.
% The function CLOSELOOP replaces the feedback input with a direct
% connection from the output layer.
netc = closeloop(net);
netc.name = [net.name ' - Closed Loop'];
view(netc)
[xc,xic,aic,tc] = preparets(netc,X,{},T);
yc = netc(xc,xic,aic);
closedLoopPerformance = perform(net,tc,yc)
% Step-Ahead Prediction Network
% For some applications it helps to get the prediction a timestep early.
% The original network returns predicted y(t+1) at the same time it is
% given y(t+1). For some applications such as decision making, it would
% help to have predicted y(t+1) once y(t) is available, but before the
% actual y(t+1) occurs. The network can be made to return its output a
% timestep early by removing one delay so that its minimal tap delay is now
% 0 instead of 1. The new network returns the same outputs as the original
% network, but outputs are shifted left one timestep.
nets = removedelay(net);
nets.name = [net.name ' - Predict One Step Ahead'];
view(nets)
[xs,xis,ais,ts] = preparets(nets,X,{},T);
ys = nets(xs,xis,ais);
stepAheadPerformance = perform(nets,ts,ys)

Community Treasure Hunt

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

Start Hunting!