mike_mike asked . 2021-07-13

MLP classification: what is the problem in my code?

I would like to understand why the neural network with MLP I built works badly. The network should be a universal classifier because it has two hidden layers but, with the data set I use, my neural network does not train well. My network is built using
  1. in the first and second layers a sigmoidal transfer function
  2. in the output layer a soft max function"inputs" file is a 3x120 matrix: 3 features and 120 observations" targets" file is a 3x120 matrix (representative of 3 different classes).
In the example code I used a network with 40 neurons in the first layer and 20 in the second layer.
I notice two anomalies
  1. if I perform view (net) I see that the number of outputs of the output layer is 2 while the output box is 3: what does this mean and why Matlab does this?
  2. in the output layer a soft max functionIf I do sum (net ([i1;i2; i3]) I have a value different from 1 but it should be 1 because in the last layer there is a softmax function.
In the following I write my code while I attach inputs and outputs file
   Choose a Training Function
  % For a list of all training functions type: help nntrain
  % 'trainlm' is usually fastest.
  % 'trainbr' takes longer but may be better for challenging problems.
  % 'trainscg' uses less memory. Suitable in low memory situations.
  trainFcn = 'trainbr';  % Scaled conjugate gradient backpropagation.

% Create a Pattern Recognition Network
hiddenLayerSize = [40 20];

net=feedforwardnet(hiddenLayerSize);%crea rete feedforward 
%imposta funzione trasferimento

net.layers{1}.transferFcn = 'tansig'
net.layers{2}.transferFcn = 'tansig'
net.layers{3}.transferFcn = 'softmax'

% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;

% Train the Network
[net,tr] = train(net,x,t);

% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
tind = vec2ind(t);
yind = vec2ind(y);
percentErrors = sum(tind ~= yind)/numel(tind);

% View the Network
view(net)

% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
figure, plotconfusion(t,y)
%figure, plotroc(t,y)

 

recognition pattern , matlab , deep learning

Expert Answer

Neeta Dsouza answered . 2024-12-21 00:35:19

There are too many basic concepts of which you are unaware. Unfortunately, I only have time to list some of them.
 
1. One hidden layer is sufficient unless you have SPECIFIC operations you wish to perform (e.g., specific image feature extraction).
 
2. Using a validation subset helps prevent poor performance on nontraining (validation, testing and unseen) data.
 
3. Too many weights can cause instability. In particular, poor performance on nontraining data (NN vendors MUST be crucially aware of this ($$$!!!)).
 
4. It is best to stay as close as possible to the MATLAB example code and default parameter values found in the help and doc documentation.
 
5. A quick look at my QUICKIES posts in the NEWSREADER may help understand what few changes are really necessary.
 
6. Think in terms of the example code and using multiple initial random weight trials to minimize the number of hidden nodes subject to obtaining a good performance on all of the data (e.g.
 mse(t-y) <= 0.01*mse(t-mean(t,2))
(Obviously comparing your design with the naïve attempt to use the best constant value for the model).
 
I have quite a few tutorials in the NEWSREADER which may help.


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.