KERAS “sparse_categorical_crossentropy” question





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















As an input a have a float 1.0 or 0.0. When I try to predict with my model and the sparse_categorical_crossentropy loss I get something like:
[[0.4846592 0.5153408]].



How do I know what category it predicts?










share|improve this question































    0















    As an input a have a float 1.0 or 0.0. When I try to predict with my model and the sparse_categorical_crossentropy loss I get something like:
    [[0.4846592 0.5153408]].



    How do I know what category it predicts?










    share|improve this question



























      0












      0








      0








      As an input a have a float 1.0 or 0.0. When I try to predict with my model and the sparse_categorical_crossentropy loss I get something like:
      [[0.4846592 0.5153408]].



      How do I know what category it predicts?










      share|improve this question
















      As an input a have a float 1.0 or 0.0. When I try to predict with my model and the sparse_categorical_crossentropy loss I get something like:
      [[0.4846592 0.5153408]].



      How do I know what category it predicts?







      python tensorflow machine-learning keras loss






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 12:57









      today

      11.7k22441




      11.7k22441










      asked Nov 23 '18 at 12:40









      user9468014user9468014

      5110




      5110
























          1 Answer
          1






          active

          oldest

          votes


















          3














          These numbers you see are the probability of each class for the given input sample. For example, [[0.4846592 0.5153408]] means that the given sample belongs to class 0 with probability of around 0.48 and it belongs to class 1 with probability of around 0.51. So you want to take the class with the highest probability and therefore you can use np.argmax to find which index (i.e. 0 or 1) is the maximum one:



          import numpy as np

          pred_class = np.argmax(probs, axis=-1)


          Further, this has nothing to do with the loss function of the model. These probabilities are given by the last layer in your model which is very likely that it uses softmax as the activation function to normalize the output as a probability distribution.






          share|improve this answer
























          • cool thanks for the perfect explanation!

            – user9468014
            Nov 23 '18 at 13:16












          Your Answer






          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: "1"
          };
          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
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446905%2fkeras-sparse-categorical-crossentropy-question%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









          3














          These numbers you see are the probability of each class for the given input sample. For example, [[0.4846592 0.5153408]] means that the given sample belongs to class 0 with probability of around 0.48 and it belongs to class 1 with probability of around 0.51. So you want to take the class with the highest probability and therefore you can use np.argmax to find which index (i.e. 0 or 1) is the maximum one:



          import numpy as np

          pred_class = np.argmax(probs, axis=-1)


          Further, this has nothing to do with the loss function of the model. These probabilities are given by the last layer in your model which is very likely that it uses softmax as the activation function to normalize the output as a probability distribution.






          share|improve this answer
























          • cool thanks for the perfect explanation!

            – user9468014
            Nov 23 '18 at 13:16
















          3














          These numbers you see are the probability of each class for the given input sample. For example, [[0.4846592 0.5153408]] means that the given sample belongs to class 0 with probability of around 0.48 and it belongs to class 1 with probability of around 0.51. So you want to take the class with the highest probability and therefore you can use np.argmax to find which index (i.e. 0 or 1) is the maximum one:



          import numpy as np

          pred_class = np.argmax(probs, axis=-1)


          Further, this has nothing to do with the loss function of the model. These probabilities are given by the last layer in your model which is very likely that it uses softmax as the activation function to normalize the output as a probability distribution.






          share|improve this answer
























          • cool thanks for the perfect explanation!

            – user9468014
            Nov 23 '18 at 13:16














          3












          3








          3







          These numbers you see are the probability of each class for the given input sample. For example, [[0.4846592 0.5153408]] means that the given sample belongs to class 0 with probability of around 0.48 and it belongs to class 1 with probability of around 0.51. So you want to take the class with the highest probability and therefore you can use np.argmax to find which index (i.e. 0 or 1) is the maximum one:



          import numpy as np

          pred_class = np.argmax(probs, axis=-1)


          Further, this has nothing to do with the loss function of the model. These probabilities are given by the last layer in your model which is very likely that it uses softmax as the activation function to normalize the output as a probability distribution.






          share|improve this answer













          These numbers you see are the probability of each class for the given input sample. For example, [[0.4846592 0.5153408]] means that the given sample belongs to class 0 with probability of around 0.48 and it belongs to class 1 with probability of around 0.51. So you want to take the class with the highest probability and therefore you can use np.argmax to find which index (i.e. 0 or 1) is the maximum one:



          import numpy as np

          pred_class = np.argmax(probs, axis=-1)


          Further, this has nothing to do with the loss function of the model. These probabilities are given by the last layer in your model which is very likely that it uses softmax as the activation function to normalize the output as a probability distribution.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 12:55









          todaytoday

          11.7k22441




          11.7k22441













          • cool thanks for the perfect explanation!

            – user9468014
            Nov 23 '18 at 13:16



















          • cool thanks for the perfect explanation!

            – user9468014
            Nov 23 '18 at 13:16

















          cool thanks for the perfect explanation!

          – user9468014
          Nov 23 '18 at 13:16





          cool thanks for the perfect explanation!

          – user9468014
          Nov 23 '18 at 13:16




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • 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.


          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%2fstackoverflow.com%2fquestions%2f53446905%2fkeras-sparse-categorical-crossentropy-question%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

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          Origin of the phrase “under your belt”?