How can we Convert Target Labels for Multiclass Output in a Neural Network?












3












$begingroup$


Please someone give me a clear idea about my stack:



For reference, see the previous question made by someone else (https://stackoverflow.com/questions/19593362/ann-multiple-vs-single-outputs) about the multiclass output case.



I am trying to classify data as one of A, B, C, and D.



In an answer given to the question above, it is suggested that we can train our network on labeled data, but convert all "A" labels to [1 0 0 0], all "B" labels to [0 1 0 0], "C" labels to [0 0 1 0], and "D" labels to [0 0 0 1]. (This is called a "one-hot" encoding.).



My question is: how can we convert these target labels in MATLAB code? (Our output target is in this case one-hot coding as explained above.)



Let's say, for example:



 data= xlsread ('disease');
input = data (1:75,1:10);
target = data (1:75, 11);


How can we define this target to be those labels??



Many thanks in advance.










share|cite|improve this question











$endgroup$

















    3












    $begingroup$


    Please someone give me a clear idea about my stack:



    For reference, see the previous question made by someone else (https://stackoverflow.com/questions/19593362/ann-multiple-vs-single-outputs) about the multiclass output case.



    I am trying to classify data as one of A, B, C, and D.



    In an answer given to the question above, it is suggested that we can train our network on labeled data, but convert all "A" labels to [1 0 0 0], all "B" labels to [0 1 0 0], "C" labels to [0 0 1 0], and "D" labels to [0 0 0 1]. (This is called a "one-hot" encoding.).



    My question is: how can we convert these target labels in MATLAB code? (Our output target is in this case one-hot coding as explained above.)



    Let's say, for example:



     data= xlsread ('disease');
    input = data (1:75,1:10);
    target = data (1:75, 11);


    How can we define this target to be those labels??



    Many thanks in advance.










    share|cite|improve this question











    $endgroup$















      3












      3








      3


      1



      $begingroup$


      Please someone give me a clear idea about my stack:



      For reference, see the previous question made by someone else (https://stackoverflow.com/questions/19593362/ann-multiple-vs-single-outputs) about the multiclass output case.



      I am trying to classify data as one of A, B, C, and D.



      In an answer given to the question above, it is suggested that we can train our network on labeled data, but convert all "A" labels to [1 0 0 0], all "B" labels to [0 1 0 0], "C" labels to [0 0 1 0], and "D" labels to [0 0 0 1]. (This is called a "one-hot" encoding.).



      My question is: how can we convert these target labels in MATLAB code? (Our output target is in this case one-hot coding as explained above.)



      Let's say, for example:



       data= xlsread ('disease');
      input = data (1:75,1:10);
      target = data (1:75, 11);


      How can we define this target to be those labels??



      Many thanks in advance.










      share|cite|improve this question











      $endgroup$




      Please someone give me a clear idea about my stack:



      For reference, see the previous question made by someone else (https://stackoverflow.com/questions/19593362/ann-multiple-vs-single-outputs) about the multiclass output case.



      I am trying to classify data as one of A, B, C, and D.



      In an answer given to the question above, it is suggested that we can train our network on labeled data, but convert all "A" labels to [1 0 0 0], all "B" labels to [0 1 0 0], "C" labels to [0 0 1 0], and "D" labels to [0 0 0 1]. (This is called a "one-hot" encoding.).



      My question is: how can we convert these target labels in MATLAB code? (Our output target is in this case one-hot coding as explained above.)



      Let's say, for example:



       data= xlsread ('disease');
      input = data (1:75,1:10);
      target = data (1:75, 11);


      How can we define this target to be those labels??



      Many thanks in advance.







      matlab neural-networks






      share|cite|improve this question















      share|cite|improve this question













      share|cite|improve this question




      share|cite|improve this question








      edited May 23 '17 at 12:39









      Community

      1




      1










      asked Oct 24 '14 at 4:01









      valerievalerie

      17211




      17211






















          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          if target is a column vector of strings of length m , and diseases is a row vector of labels of length n, then you can create a logical array classlabels of size(m,n) using the code below.



          classlabels = (target==diseases)






          share|cite|improve this answer









          $endgroup$














            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "69"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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
            },
            noCode: true, onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f988599%2fhow-can-we-convert-target-labels-for-multiclass-output-in-a-neural-network%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$

            if target is a column vector of strings of length m , and diseases is a row vector of labels of length n, then you can create a logical array classlabels of size(m,n) using the code below.



            classlabels = (target==diseases)






            share|cite|improve this answer









            $endgroup$


















              0












              $begingroup$

              if target is a column vector of strings of length m , and diseases is a row vector of labels of length n, then you can create a logical array classlabels of size(m,n) using the code below.



              classlabels = (target==diseases)






              share|cite|improve this answer









              $endgroup$
















                0












                0








                0





                $begingroup$

                if target is a column vector of strings of length m , and diseases is a row vector of labels of length n, then you can create a logical array classlabels of size(m,n) using the code below.



                classlabels = (target==diseases)






                share|cite|improve this answer









                $endgroup$



                if target is a column vector of strings of length m , and diseases is a row vector of labels of length n, then you can create a logical array classlabels of size(m,n) using the code below.



                classlabels = (target==diseases)







                share|cite|improve this answer












                share|cite|improve this answer



                share|cite|improve this answer










                answered Apr 13 '17 at 13:51









                user1319128user1319128

                1011




                1011






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Mathematics 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%2fmath.stackexchange.com%2fquestions%2f988599%2fhow-can-we-convert-target-labels-for-multiclass-output-in-a-neural-network%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

                    Human spaceflight

                    Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

                    File:DeusFollowingSea.jpg