How to export predicted multi-output data from trained neural network?
Afficher commentaires plus anciens
Hi, I have trained a feedforward neural network and would like to use it to simulate and predict the output using new input data. However, my code only able to predict single output data. Any thing wrong with my coding for simulation of neural network (code that highlight in BOLD)? How to export multioutput datas to workspace by using coding? Below is my code for neural network. Can anybody help me to solve this?
Develop Neural Network Model
%Import data
inputs=dlmread('Inputs2.txt', '\t', 1, 0); %input data
targets=dlmread('Targets2.txt', '\t', 1, 0); %target data
inputrep=repmat(inputs,4,1); %replicate input data
targetrep=repmat(targets,4,1); %replicate target data
inputrep = inputrep'; %transpose the data
targetrep = targetrep';
[inputrepn, inputreps]=mapminmax(inputrep); %normalize the data
[targetrepn, targetreps]=mapminmax(targetrep);
trainFcn = 'trainlm'; %use the Levenberg-Marquardt algorithm
%Train the networks
for i=1:30 %vary number of hidden layer neurons from 1 to 100
hiddenLayerSize = i; %number of hidden layer neurons
net = fitnet(hiddenLayerSize,trainFcn); %create a fitting network
net.divideParam.trainRatio = 70/100; %use 70% of data for training
net.divideParam.valRatio = 15/100; %15% for validation
net.divideParam.testRatio = 15/100; %15% for testing
[net,tr] = train(net,inputrepn,targetrepn); % train the network
outputs = net(inputrepn(:,tr.testInd)); %simulate 15% test data
rmse15(i)=sqrt(mean((outputs-targetrepn(tr.testInd)).^2)); %RMSE for 15% random test data
r15(i)=regression(targetrepn(tr.testInd), outputs);
save(['networks\net' num2str(i)],'net'); %save the network in networks folder
end
%Plot the RMSEs
plot(1:30, rmse15, 'b*-');
legend('Random'); xlabel('Number of hidden layer neurons');
ylabel('RMSE (^oC)');
%Save the RMSEs
fid=fopen('rmse.txt', 'wt');
fprintf(fid, 'Nh\t RMSE15\t');
fprintf(fid, '%4.0f\t %f\t %f\n', [1:30; rmse15]);
fclose all;
Simulate Neural Network Model
%Import data
inputnew =dlmread('Inputs3.txt', '\t', 1, 0); %input data
inputnew = inputnew'; %transpose the data
[inputnewn, inputnews]= mapminmax(inputnew); %normalize the data
%simulate network to predict output
yn = sim(net,inputnewn);
y = mapminmax('reverse',yn,targetreps); %denormalize data
y = y'; %transpose the data
%Save the predicted outputs
fid=fopen('y.txt', 'wt');
fprintf(fid, 'Yield\t O/C\t C/N\t');
fprintf(fid, '%4.0f\t %4.0f\t %4.0f\t %f\n', [1:14; rmse15]);
fclose all;
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Deep Learning Toolbox dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!