Difference between fitrnet and fitnet

60 ビュー (過去 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 Center および File ExchangeSequence 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