How to use this trained programme to get outputs for new inputs?
조회 수: 7 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
Jayanti
2025년 7월 7일
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!
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!