Neural Network Classifier in MatlabSimple Java Neural NetworkNeural Network in HaskellA simple fully...

Jumping Numbers

Planet at the end of Solo: A Star Wars Story

"On one hand" vs "on the one hand."

If I delete my router's history can my ISP still provide it to my parents?

What to do when being responsible for data protection in your lab, yet advice is ignored?

Eww, those bytes are gross

It took me a lot of time to make this, pls like. (YouTube Comments #1)

Can a person refuse a presidential pardon?

Why is working on the same position for more than 15 years not a red flag?

Strange Sign on Lab Door

Issues with new Macs: Hardware makes them difficult for me to use. What options might be available in the future?

How to avoid being sexist when trying to employ someone to function in a very sexist environment?

Unwarranted claim of higher degree of accuracy in zircon geochronology

What's a good word to describe a public place that looks like it wouldn't be rough?

What do you call a fact that doesn't match the settings?

What makes the Forgotten Realms "forgotten"?

How do you funnel food off a cutting board?

Can polymorphing monsters spam their ability to effectively give themselves a massive health pool?

Reference on complex cobordism

Tikzing a circled star

Why did Bush enact a completely different foreign policy to that which he espoused during the 2000 Presidential election campaign?

How would one buy a used TIE Fighter or X-Wing?

How should I handle players who ignore the session zero agreement?

Quenching swords in dragon blood; why?



Neural Network Classifier in Matlab


Simple Java Neural NetworkNeural Network in HaskellA simple fully connected ANN moduleKeras: multiclass classification with Recurrent Neural NetworkBare minimum neural network, random weight update etcSelf-written Neural NetworkMatlab Code for Convolutional Neural NetworksDeep Neural Network in PythonSimple Neural Network in CNeural Network Backpropagation













3












$begingroup$


I am trying to build a neural network classifier. I have created a neural network with 1 hidden layer (25 hidden neurons) and 1 output layer (1 neuron/binary classification).



The dataset I am using has the following dimensions:



size(X_Train): 125973 x 122
size(Y_Train): 125973 x 1
size(X_Test): 22543 x 122
size(Y_test): 22543 x 1


My overall goal is to compare different training functions. But I would like first to get your feedback about my code and how I improve it.



% Neural Network Binary-classification

clear ; close all; clc

%% =========== Part 1: Loading Data =============

%% Load Training Data
fprintf('Loading Data ...n');

load('dataset.mat'); % training data stored in arrays X, y
X_training=X_training';
Y_training=Y_training';
X_testing=X_testing';
Y_testing=Y_testing';

%% Create the neural network
% 1, 2: ONE input, TWO layers (one hidden layer and one output layer)
% [1; 1]: both 1st and 2nd layer have a bias node
% [1; 0]: the input is a source for the 1st layer
% [0 0; 1 0]: the 1st layer is a source for the 2nd layer
% [0 1]: the 2nd layer is a source for your output
net = network(1, 2, [1; 1], [1; 0], [0 0; 1 0], [0 1]);
net.inputs{1}.size = 122; % input size
net.layers{1}.size = 25; % hidden layer size
net.layers{2}.size = 1; % output layer size

%% Transfer function in layers
net.layers{1}.transferFcn = 'logsig';
net.layers{2}.transferFcn = 'logsig';

net.layers{1}.initFcn = 'initnw';
net.layers{2}.initFcn = 'initnw';

net=init(net);

%% divide data into training and test
net.divideFcn= 'dividerand';
net.divideParam.trainRatio = 60/100; % 80% training
net.divideParam.valRatio = 20/100; % 20% validation set
net.divideParam.testRatio = 20/100; % 20% validation set

net.performFcn = 'crossentropy';

%% Training functions
net.trainFcn = 'trainscg'; %Scaled conjugate gradient backpropagation

%% Train the neural network
[net,tr] = train(net,X_training,Y_training); % return the network and training record

%% Test the Neural Network on the training set
outputs = net(X_training);
errors = gsubtract(Y_training,outputs);
performance = perform(net,Y_training,outputs);

%% Plots (%training)
figure, plotperform(tr)
figure, plottrainstate(tr)

%% Test the Neural Network on the testing test
outputs1 = net(X_testing);
errors1 = gsubtract(Y_testing,outputs1);
performance1 = perform(net,Y_testing,outputs1);

figure, plotconfusion(Y_testing,outputs1)
figure, ploterrhist(errors1)


Below if the validation curve.



enter image description here



Confusion Matrix (Training set)



enter image description here



Confusion Matrix (Testing set)
enter image description here



Any remarks?



Edit:



I have used feature scaling or normalization:



net.performParam.normalization = 'standard';


which improved the overall accuracy:enter image description here



For more information, I have added the error histogram:



enter image description here









share











$endgroup$

















    3












    $begingroup$


    I am trying to build a neural network classifier. I have created a neural network with 1 hidden layer (25 hidden neurons) and 1 output layer (1 neuron/binary classification).



    The dataset I am using has the following dimensions:



    size(X_Train): 125973 x 122
    size(Y_Train): 125973 x 1
    size(X_Test): 22543 x 122
    size(Y_test): 22543 x 1


    My overall goal is to compare different training functions. But I would like first to get your feedback about my code and how I improve it.



    % Neural Network Binary-classification

    clear ; close all; clc

    %% =========== Part 1: Loading Data =============

    %% Load Training Data
    fprintf('Loading Data ...n');

    load('dataset.mat'); % training data stored in arrays X, y
    X_training=X_training';
    Y_training=Y_training';
    X_testing=X_testing';
    Y_testing=Y_testing';

    %% Create the neural network
    % 1, 2: ONE input, TWO layers (one hidden layer and one output layer)
    % [1; 1]: both 1st and 2nd layer have a bias node
    % [1; 0]: the input is a source for the 1st layer
    % [0 0; 1 0]: the 1st layer is a source for the 2nd layer
    % [0 1]: the 2nd layer is a source for your output
    net = network(1, 2, [1; 1], [1; 0], [0 0; 1 0], [0 1]);
    net.inputs{1}.size = 122; % input size
    net.layers{1}.size = 25; % hidden layer size
    net.layers{2}.size = 1; % output layer size

    %% Transfer function in layers
    net.layers{1}.transferFcn = 'logsig';
    net.layers{2}.transferFcn = 'logsig';

    net.layers{1}.initFcn = 'initnw';
    net.layers{2}.initFcn = 'initnw';

    net=init(net);

    %% divide data into training and test
    net.divideFcn= 'dividerand';
    net.divideParam.trainRatio = 60/100; % 80% training
    net.divideParam.valRatio = 20/100; % 20% validation set
    net.divideParam.testRatio = 20/100; % 20% validation set

    net.performFcn = 'crossentropy';

    %% Training functions
    net.trainFcn = 'trainscg'; %Scaled conjugate gradient backpropagation

    %% Train the neural network
    [net,tr] = train(net,X_training,Y_training); % return the network and training record

    %% Test the Neural Network on the training set
    outputs = net(X_training);
    errors = gsubtract(Y_training,outputs);
    performance = perform(net,Y_training,outputs);

    %% Plots (%training)
    figure, plotperform(tr)
    figure, plottrainstate(tr)

    %% Test the Neural Network on the testing test
    outputs1 = net(X_testing);
    errors1 = gsubtract(Y_testing,outputs1);
    performance1 = perform(net,Y_testing,outputs1);

    figure, plotconfusion(Y_testing,outputs1)
    figure, ploterrhist(errors1)


    Below if the validation curve.



    enter image description here



    Confusion Matrix (Training set)



    enter image description here



    Confusion Matrix (Testing set)
    enter image description here



    Any remarks?



    Edit:



    I have used feature scaling or normalization:



    net.performParam.normalization = 'standard';


    which improved the overall accuracy:enter image description here



    For more information, I have added the error histogram:



    enter image description here









    share











    $endgroup$















      3












      3








      3





      $begingroup$


      I am trying to build a neural network classifier. I have created a neural network with 1 hidden layer (25 hidden neurons) and 1 output layer (1 neuron/binary classification).



      The dataset I am using has the following dimensions:



      size(X_Train): 125973 x 122
      size(Y_Train): 125973 x 1
      size(X_Test): 22543 x 122
      size(Y_test): 22543 x 1


      My overall goal is to compare different training functions. But I would like first to get your feedback about my code and how I improve it.



      % Neural Network Binary-classification

      clear ; close all; clc

      %% =========== Part 1: Loading Data =============

      %% Load Training Data
      fprintf('Loading Data ...n');

      load('dataset.mat'); % training data stored in arrays X, y
      X_training=X_training';
      Y_training=Y_training';
      X_testing=X_testing';
      Y_testing=Y_testing';

      %% Create the neural network
      % 1, 2: ONE input, TWO layers (one hidden layer and one output layer)
      % [1; 1]: both 1st and 2nd layer have a bias node
      % [1; 0]: the input is a source for the 1st layer
      % [0 0; 1 0]: the 1st layer is a source for the 2nd layer
      % [0 1]: the 2nd layer is a source for your output
      net = network(1, 2, [1; 1], [1; 0], [0 0; 1 0], [0 1]);
      net.inputs{1}.size = 122; % input size
      net.layers{1}.size = 25; % hidden layer size
      net.layers{2}.size = 1; % output layer size

      %% Transfer function in layers
      net.layers{1}.transferFcn = 'logsig';
      net.layers{2}.transferFcn = 'logsig';

      net.layers{1}.initFcn = 'initnw';
      net.layers{2}.initFcn = 'initnw';

      net=init(net);

      %% divide data into training and test
      net.divideFcn= 'dividerand';
      net.divideParam.trainRatio = 60/100; % 80% training
      net.divideParam.valRatio = 20/100; % 20% validation set
      net.divideParam.testRatio = 20/100; % 20% validation set

      net.performFcn = 'crossentropy';

      %% Training functions
      net.trainFcn = 'trainscg'; %Scaled conjugate gradient backpropagation

      %% Train the neural network
      [net,tr] = train(net,X_training,Y_training); % return the network and training record

      %% Test the Neural Network on the training set
      outputs = net(X_training);
      errors = gsubtract(Y_training,outputs);
      performance = perform(net,Y_training,outputs);

      %% Plots (%training)
      figure, plotperform(tr)
      figure, plottrainstate(tr)

      %% Test the Neural Network on the testing test
      outputs1 = net(X_testing);
      errors1 = gsubtract(Y_testing,outputs1);
      performance1 = perform(net,Y_testing,outputs1);

      figure, plotconfusion(Y_testing,outputs1)
      figure, ploterrhist(errors1)


      Below if the validation curve.



      enter image description here



      Confusion Matrix (Training set)



      enter image description here



      Confusion Matrix (Testing set)
      enter image description here



      Any remarks?



      Edit:



      I have used feature scaling or normalization:



      net.performParam.normalization = 'standard';


      which improved the overall accuracy:enter image description here



      For more information, I have added the error histogram:



      enter image description here









      share











      $endgroup$




      I am trying to build a neural network classifier. I have created a neural network with 1 hidden layer (25 hidden neurons) and 1 output layer (1 neuron/binary classification).



      The dataset I am using has the following dimensions:



      size(X_Train): 125973 x 122
      size(Y_Train): 125973 x 1
      size(X_Test): 22543 x 122
      size(Y_test): 22543 x 1


      My overall goal is to compare different training functions. But I would like first to get your feedback about my code and how I improve it.



      % Neural Network Binary-classification

      clear ; close all; clc

      %% =========== Part 1: Loading Data =============

      %% Load Training Data
      fprintf('Loading Data ...n');

      load('dataset.mat'); % training data stored in arrays X, y
      X_training=X_training';
      Y_training=Y_training';
      X_testing=X_testing';
      Y_testing=Y_testing';

      %% Create the neural network
      % 1, 2: ONE input, TWO layers (one hidden layer and one output layer)
      % [1; 1]: both 1st and 2nd layer have a bias node
      % [1; 0]: the input is a source for the 1st layer
      % [0 0; 1 0]: the 1st layer is a source for the 2nd layer
      % [0 1]: the 2nd layer is a source for your output
      net = network(1, 2, [1; 1], [1; 0], [0 0; 1 0], [0 1]);
      net.inputs{1}.size = 122; % input size
      net.layers{1}.size = 25; % hidden layer size
      net.layers{2}.size = 1; % output layer size

      %% Transfer function in layers
      net.layers{1}.transferFcn = 'logsig';
      net.layers{2}.transferFcn = 'logsig';

      net.layers{1}.initFcn = 'initnw';
      net.layers{2}.initFcn = 'initnw';

      net=init(net);

      %% divide data into training and test
      net.divideFcn= 'dividerand';
      net.divideParam.trainRatio = 60/100; % 80% training
      net.divideParam.valRatio = 20/100; % 20% validation set
      net.divideParam.testRatio = 20/100; % 20% validation set

      net.performFcn = 'crossentropy';

      %% Training functions
      net.trainFcn = 'trainscg'; %Scaled conjugate gradient backpropagation

      %% Train the neural network
      [net,tr] = train(net,X_training,Y_training); % return the network and training record

      %% Test the Neural Network on the training set
      outputs = net(X_training);
      errors = gsubtract(Y_training,outputs);
      performance = perform(net,Y_training,outputs);

      %% Plots (%training)
      figure, plotperform(tr)
      figure, plottrainstate(tr)

      %% Test the Neural Network on the testing test
      outputs1 = net(X_testing);
      errors1 = gsubtract(Y_testing,outputs1);
      performance1 = perform(net,Y_testing,outputs1);

      figure, plotconfusion(Y_testing,outputs1)
      figure, ploterrhist(errors1)


      Below if the validation curve.



      enter image description here



      Confusion Matrix (Training set)



      enter image description here



      Confusion Matrix (Testing set)
      enter image description here



      Any remarks?



      Edit:



      I have used feature scaling or normalization:



      net.performParam.normalization = 'standard';


      which improved the overall accuracy:enter image description here



      For more information, I have added the error histogram:



      enter image description here







      machine-learning matlab neural-network





      share














      share












      share



      share








      edited Nov 19 '18 at 11:51







      U. User

















      asked Nov 18 '18 at 20:08









      U. UserU. User

      336




      336






















          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          Welcome to codereview SE!





          Not a code reviewer, but I'd like to comment on the design of your network, which you certainly seem to be doing just fine.







          • It might be rather difficult to make any judgment, given that the application is undefined, while it seems you are designing a neural-network based detector.


          • Numerically speaking, you might focus on your validation performance, by constantly redesigning your network architecture
            (e.g., number of hidden layers, number of hidden neurons, reducing and
            increasing batch sizes, training functions/methods as you mentioned,
            etc.), input preprocessing (e.g., smoothing, input interpolation or
            extrapolation in case possible, artifact removal, etc.).


          • Not knowing what your datasets might be and how sophisticated that may be, you may focus on 10^-3 to 10^-6 convergence range. It might increase the performance (e.g., confusion matrices) of your network.







          Overall, it seems your input is pretty stochastic, input preprocessing may be worth looking into.





          Best wishes!






          share|improve this answer









          $endgroup$













            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "196"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207937%2fneural-network-classifier-in-matlab%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0












            $begingroup$

            Welcome to codereview SE!





            Not a code reviewer, but I'd like to comment on the design of your network, which you certainly seem to be doing just fine.







            • It might be rather difficult to make any judgment, given that the application is undefined, while it seems you are designing a neural-network based detector.


            • Numerically speaking, you might focus on your validation performance, by constantly redesigning your network architecture
              (e.g., number of hidden layers, number of hidden neurons, reducing and
              increasing batch sizes, training functions/methods as you mentioned,
              etc.), input preprocessing (e.g., smoothing, input interpolation or
              extrapolation in case possible, artifact removal, etc.).


            • Not knowing what your datasets might be and how sophisticated that may be, you may focus on 10^-3 to 10^-6 convergence range. It might increase the performance (e.g., confusion matrices) of your network.







            Overall, it seems your input is pretty stochastic, input preprocessing may be worth looking into.





            Best wishes!






            share|improve this answer









            $endgroup$


















              0












              $begingroup$

              Welcome to codereview SE!





              Not a code reviewer, but I'd like to comment on the design of your network, which you certainly seem to be doing just fine.







              • It might be rather difficult to make any judgment, given that the application is undefined, while it seems you are designing a neural-network based detector.


              • Numerically speaking, you might focus on your validation performance, by constantly redesigning your network architecture
                (e.g., number of hidden layers, number of hidden neurons, reducing and
                increasing batch sizes, training functions/methods as you mentioned,
                etc.), input preprocessing (e.g., smoothing, input interpolation or
                extrapolation in case possible, artifact removal, etc.).


              • Not knowing what your datasets might be and how sophisticated that may be, you may focus on 10^-3 to 10^-6 convergence range. It might increase the performance (e.g., confusion matrices) of your network.







              Overall, it seems your input is pretty stochastic, input preprocessing may be worth looking into.





              Best wishes!






              share|improve this answer









              $endgroup$
















                0












                0








                0





                $begingroup$

                Welcome to codereview SE!





                Not a code reviewer, but I'd like to comment on the design of your network, which you certainly seem to be doing just fine.







                • It might be rather difficult to make any judgment, given that the application is undefined, while it seems you are designing a neural-network based detector.


                • Numerically speaking, you might focus on your validation performance, by constantly redesigning your network architecture
                  (e.g., number of hidden layers, number of hidden neurons, reducing and
                  increasing batch sizes, training functions/methods as you mentioned,
                  etc.), input preprocessing (e.g., smoothing, input interpolation or
                  extrapolation in case possible, artifact removal, etc.).


                • Not knowing what your datasets might be and how sophisticated that may be, you may focus on 10^-3 to 10^-6 convergence range. It might increase the performance (e.g., confusion matrices) of your network.







                Overall, it seems your input is pretty stochastic, input preprocessing may be worth looking into.





                Best wishes!






                share|improve this answer









                $endgroup$



                Welcome to codereview SE!





                Not a code reviewer, but I'd like to comment on the design of your network, which you certainly seem to be doing just fine.







                • It might be rather difficult to make any judgment, given that the application is undefined, while it seems you are designing a neural-network based detector.


                • Numerically speaking, you might focus on your validation performance, by constantly redesigning your network architecture
                  (e.g., number of hidden layers, number of hidden neurons, reducing and
                  increasing batch sizes, training functions/methods as you mentioned,
                  etc.), input preprocessing (e.g., smoothing, input interpolation or
                  extrapolation in case possible, artifact removal, etc.).


                • Not knowing what your datasets might be and how sophisticated that may be, you may focus on 10^-3 to 10^-6 convergence range. It might increase the performance (e.g., confusion matrices) of your network.







                Overall, it seems your input is pretty stochastic, input preprocessing may be worth looking into.





                Best wishes!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 16 mins ago









                EmmaEmma

                1196




                1196






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Code Review Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207937%2fneural-network-classifier-in-matlab%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Webac Holding Inhaltsverzeichnis Geschichte | Organisationsstruktur | Tochterfirmen |...

                    What's the meaning of a knight fighting a snail in medieval book illustrations?What is the meaning of a glove...

                    Salamanca Inhaltsverzeichnis Lage und Klima | Bevölkerungsentwicklung | Geschichte | Kultur und...