Using a trained ANN model for new set of inputs
Show older comments
I have used the following code to train and save a neural network model in matlab.
clear
clc
pwd;
ImportingData = [pwd,'\Data.csv'];
data = readtable(ImportingData);
%% Data Separation
Inputs = [data.SV.';data.SF.'];
Responses = [data.PDC.'; data.JLwS.'; data.JLwoS.'; data.P.'];
trainFcn = 'trainbr'; % Levenberg-Marquardt backpropagation.
hiddenLayerSize = [8,24];
net = fitnet(hiddenLayerSize,trainFcn);
net.layers{1}.transferFcn = 'tansig';
net.layers{2}.transferFcn = 'tansig';
net.layers{3}.transferFcn = 'tansig';
view(net);
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
[net,tr] = train(net,Inputs,Responses);
Predictions = net(Inputs);
Errors = gsubtract(Responses,Predictions);
Performance = perform(net,Responses,Predictions);
RE = (Predictions-Responses)./Responses.*100;
R2_PDC = 1 - (sum((Responses(1,:)-Predictions(1,:)).^2))/(sum((Responses(1,:)-mean(Responses(1,:))).^2));
R2_JLwS = 1 - (sum((Responses(2,:)-Predictions(2,:)).^2))/(sum((Responses(2,:)-mean(Responses(2,:))).^2));
R2_JLwoS = 1 - (sum((Responses(3,:)-Predictions(3,:)).^2))/(sum((Responses(3,:)-mean(Responses(3,:))).^2));
R2_P = 1 - (sum((Responses(4,:)-Predictions(4,:)).^2))/(sum((Responses(4,:)-mean(Responses(4,:))).^2));
save net
After getting the desired accuracy, I have renamed the "net.mat" file to a different name - "net_BR_8_20.mat"
Now, I want to use this renamed ANN model for a different set of inputs (different from the data fed to develop the model). I used the following set of code for this:
%% Code initialization
clear
clc
%% Importing of data
pwd;
ImportingData = [pwd,'\Data_Extrapolate.csv'];
data = readtable(ImportingData);
%% Data reading
Inputs = [data.SV.';data.SF.'];
%% ANN predictions
load net_BR_8_20
NewOutputs = net(Inputs);
But, this code is giving the same output as the training dataset with same number of rows as the i
And when I use:
net_BR_8_20(Inputs)
It says: Unrecognized function or variable 'net_BR_8_20'.
Kindly help me resolve this issue. Thank you.
Accepted Answer
More Answers (0)
Categories
Find more on Deep Learning Toolbox 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!