MATLAB: How to save neural network

load netneural network tranferabilitysave net

I have used neural network to the datasets and now if i trained network one time and now i want to apply this network to different datasets then how i can apply? I want to do this because i want to compare how efficient the transferability? I am eager to find solution.

Best Answer

clear all, close all, clc;
[x,t] = simplefit_dataset;
[I N ] = size(x)
[O N ] = size(t)
xtrn = x(1:2:N);
ttrn = t(1:2:N);
MSEtrn00 = var(ttrn',1) % Reference MSEtrn
xval = []; % No val data for Early Stopping
tval = [];
xtst = x(2:2:N); % For post training testing
ttst = t(2:2:N);
MSEtst00 = var(ttst',1) % Reference MSEtst
H = 4 % Minimized by trial & error
net = fitnet(H);
net.divideFcn = ''; % No automatic data division
net.trainParam.goal = 0.01*MSEtrn00; % Want training R^2 >= 0.99
[net tr Ytrn Etrn] = train(net,xtrn,ttrn);
ytrn = net(xtrn);
etrn = ttrn-ytrn;
MSEtrn =mse(etrn)
check1 = max(abs(ytrn - Ytrn))
check2 = max(abs(etrn - Etrn))
check3 = max(abs(MSEtrn - tr.perf(end)))
NMSEtrn = MSEtrn/MSEtrn00 % Normalized
R2trn = 1-NMSEtrn % R^2
% Save for use with other data
net01 = net;
save net01 % Save
whos net net01 % Both in workspace
pause(5)
clear net net01 % Cleared from workspace
whos % Proof
%Retrieve and use
load net01
ytst = net01(xtst);
MSEtst = mse(ttst-ytst)
R2tst = 1-MSEtst/MSEtst00
Hope this helps
Thank you for formally accepting my answer
Greg