How to use this trained programme to get outputs for new inputs?

8 visualizaciones (últimos 30 días)
Sugan
Sugan el 28 de Jul. de 2013
Respondida: Jayanti el 7 de Jul. de 2025
I modified the following 'Input-Output Fitting problem'.
inputs = Inputs;
targets = Targets;
hiddenLayerSize = 10;
net = fitnet(hiddenLayerSize);
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
net.trainFcn = 'trainlm'; % Levenberg-Marquardt
net.performFcn = 'mse'; % Mean squared error
net.plotFcns ={'plotperform','plottrainstate','ploterrhist','plotregression', 'plotfit'};
[net,tr] = train(net,inputs,targets);
outputs = net(inputs);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs) trainTargets = targets .* tr.trainMask{1};
valTargets = targets .* tr.valMask{1};
testTargets = targets .* tr.testMask{1};
view(net)
Any body can help me on this.... I have to use above programme to get outputs for new inputs. How can i proceed that?

Respuestas (1)

Jayanti
Jayanti el 7 de Jul. de 2025
Hi Sugan,
After training your neural network, you can easily use the trained model to predict outputs for new data. Since the network has already learned from your original inputs and targets, you just need to pass your new input data to the trained network object.
Assuming "newInputs" is a matrix where each column is a new input sample (with the same number of features as the original training inputs):
newInputs = [];
% Predict outputs using the trained network
newOutputs = net(newInputs);
There's no need to manually normalize or preprocess "newInputs". The trained network automatically applies the same preprocessing steps that were applied during training.
Or you can also save the model.
save('trainedModel.mat', 'net');
And later reload it and use it.
load('trainedModel.mat');
predictedOutputs = net(newInputs);
I am also attaching offical MathWorks documentation on "save" for your reference:
Happy coding!

Community Treasure Hunt

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

Start Hunting!

Translated by