Difference between fitrnet and fitnet

조회 수: 61 (최근 30일)
Alex Liu
Alex Liu 2021년 12월 19일
댓글: David Willingham 2022년 10월 27일
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.

채택된 답변

David Willingham
David Willingham 2021년 12월 20일
편집: David Willingham 2022년 5월 18일
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
Alessandro Niccolai
Alessandro Niccolai 2022년 10월 26일
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
David Willingham 2022년 10월 27일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by