Difference between fitrnet and fitnet
59 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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
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
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 Center 和 File Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!