Borrar filtros
Borrar filtros

Using a trained ANN model for new set of inputs

12 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Subraya Krishna Bhat
Subraya Krishna Bhat el 28 de Mayo de 2023
I was able to resolve this issue by renaming my trained neural network as "net" instead of "net_BR_8_20". Then by using the following code I can get new predictions for new input data
NewOutput = net(NewInput)
Perhaps, there is some naming convention for neural network files in MATLAB which I am unaware of. Kindly anyone can share this information, if available.
Thank you!

Más respuestas (0)

Categorías

Más información sobre Sequence and Numeric Feature Data Workflows en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by