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;
}
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
add a comment |
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
add a comment |
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
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
python tensorflow machine-learning keras loss
edited Nov 23 '18 at 12:57
today
11.7k22441
11.7k22441
asked Nov 23 '18 at 12:40
user9468014user9468014
5110
5110
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
cool thanks for the perfect explanation!
– user9468014
Nov 23 '18 at 13:16
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
cool thanks for the perfect explanation!
– user9468014
Nov 23 '18 at 13:16
add a comment |
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.
cool thanks for the perfect explanation!
– user9468014
Nov 23 '18 at 13:16
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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