Difference between fitrnet and fitnet
74 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Alex Liu
il 19 Dic 2021
Commentato: David Willingham
il 27 Ott 2022
When I first learn to use neural networks, I usually used nnstart toolbox, which uses fitnet. However, when I started actually to build my own neural networks with more layers and optimal hyperparameters, I found that R2021a introduced fitrnet that looks more powerful. I was wondering what is the difference between these two neural network functions.
0 Commenti
Risposta accettata
David Willingham
il 20 Dic 2021
Modificato: David Willingham
il 18 Mag 2022
Hi Alex,
In R2021a, SMLT introduced the fitting functions fitcnet and fitrnet, which train shallow classification and regression neural network models. If you'd like to customize the network, there is a newer framework for building shallow and deep neural networks. Here are 2 examples of how to do this:
David
3 Commenti
Alessandro Niccolai
il 26 Ott 2022
Dear David,
While working on Neural Network, I've compared the results of the two functions "fitrnet" and "fitnet". The results I've obtained shows that the "fitnet" function works much better both in terms of computational time and of performance.
Even usign the hyperparameter optimization of "fitrnet", the results are much less than the "fitnet". Here you can find the results I've obtained:
Neural Network - fitrnet
Elapsed time is 105.777746 seconds.
R2 = 0.99957
MSE = 0.028211%
Neural Network - fitnet
Elapsed time is 23.113578 seconds.
R2 = 0.99997
MSE = 0.00082949%
In both the cases, I've computed the performance on a different dataset.
Have you experienced something similar?
Attached you can find the input I've used and below the code that performs the comparison:
clc
clear
close all
load('trainingTest');
%% Train fitrnet
disp('Neural Network - fitrnet')
disp('-- Traninig --')
tic
Mdl = fitrnet(...
x, t, ...
'LayerSizes', [ 86 23 294], ...
'Activations', 'tanh', ...
'Lambda', 0.022295, ...
'IterationLimit', 2000, ...
'Standardize', true);
toc
disp('-- Running --')
yTest = predict(Mdl,xTest);
% R2
R2 = regress(yTest,tTest);
disp([' R2 = ',num2str(R2)])
% MSE
MSE = mean((tTest-yTest).^2)/mean(yTest)^2*100;
disp([' MSE = ',num2str(MSE),'%'])
%% Train fitnet
disp('Neural Network - fitnet')
hiddenLayers = [10 10];
nLayers = length(hiddenLayers)+1;
net = fitnet(hiddenLayers);
net.trainFcn = 'trainbr';
net.trainParam.epochs = 1000;
net.trainParam.showWindow = false;
net.trainParam.showCommandLine = false;
net.trainParam.show = 10;
net.trainParam.max_fail = 3;
net.trainParam.goal = 1e-9;
net.divideFcn = 'dividerand';
net.divideParam.testRatio = 0.15;
net.divideParam.valRatio = 0.15;
tic
[net,tr] = train(net,x',t');
toc
yTest = net(xTest')';
% R2
R2 = regress(yTest,tTest);
disp([' R2 = ',num2str(R2)])
% MSE
MSE = mean((tTest-yTest).^2)/mean(yTest)^2*100;
disp([' MSE = ',num2str(MSE),'%'])
David Willingham
il 27 Ott 2022
Hi Allesandro,
The two functions have different solver implementations under the hood. Also they have different number of layers and layers sizes.
My recommendation is that you can always try both and see which method works best for the given application.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Function Approximation and Nonlinear Regression in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!