The most used loss function in tensorflow for a binary classification?
$begingroup$
I am working on a binary classification problem using CNN model, the model designed using tensorflow framework, in most github projects that I saw, they use "softmax cross entropy with logits" v1 and v2 as loss function, my questions is:
1- why this loss method is the most used one?
2- what is the type of this function because of the name I am confused about its type.
3- what is the equation for the function? in tensorflow website the equation is not available.
tensorflow cnn image-classification
$endgroup$
add a comment |
$begingroup$
I am working on a binary classification problem using CNN model, the model designed using tensorflow framework, in most github projects that I saw, they use "softmax cross entropy with logits" v1 and v2 as loss function, my questions is:
1- why this loss method is the most used one?
2- what is the type of this function because of the name I am confused about its type.
3- what is the equation for the function? in tensorflow website the equation is not available.
tensorflow cnn image-classification
$endgroup$
add a comment |
$begingroup$
I am working on a binary classification problem using CNN model, the model designed using tensorflow framework, in most github projects that I saw, they use "softmax cross entropy with logits" v1 and v2 as loss function, my questions is:
1- why this loss method is the most used one?
2- what is the type of this function because of the name I am confused about its type.
3- what is the equation for the function? in tensorflow website the equation is not available.
tensorflow cnn image-classification
$endgroup$
I am working on a binary classification problem using CNN model, the model designed using tensorflow framework, in most github projects that I saw, they use "softmax cross entropy with logits" v1 and v2 as loss function, my questions is:
1- why this loss method is the most used one?
2- what is the type of this function because of the name I am confused about its type.
3- what is the equation for the function? in tensorflow website the equation is not available.
tensorflow cnn image-classification
tensorflow cnn image-classification
asked 21 hours ago
honar.cshonar.cs
14410
14410
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
I think there is some confusion here. Softmax is usually an activation function which you will use in your output layer, and cross-entropy is the loss function that you will use.
Softmax
This activation function outputs the probability for each class, it is defined as
$sigma(bf{y_i}) = frac{e^{bf{y_i}}}{sum_{j}{e^{bf{y_j}}}}$.
For example, in a problem with 2 class labels. Then if we have some outputs from our neural network like $y$=[3, 4] then we can get the probability of each output classes by using the softmax function on these outputs.
import numpy as np
x = [3, 4]
np.exp(x)/np.sum(np.exp(x))
[0.26894142, 0.73105858]
You will see that these are probabilities and do sum to 1.
Then we can get the class of the input by seeing which probability is higher. In this case class 2 has a probability of 73.11%, so the predicted class label, $hat{y} = 1$.
Cross-entropy
Cross-entropy is a loss function that is used for classification tasks. For binary classification it is defined as
$H(p, q) = -ylog(p) - (1-y)log(1-p)$.
Let's assume that the real class of the above example is 0, $y=0$. Then we made a mistake and you can see that
$H(p, q) = -0log(0.26894142) - (1-0)log(1-0.26894142) = 0.313$.
That is the loss that is used for backpropagation.
$endgroup$
add a comment |
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.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "557"
};
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
});
}
});
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%2fdatascience.stackexchange.com%2fquestions%2f46597%2fthe-most-used-loss-function-in-tensorflow-for-a-binary-classification%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
$begingroup$
I think there is some confusion here. Softmax is usually an activation function which you will use in your output layer, and cross-entropy is the loss function that you will use.
Softmax
This activation function outputs the probability for each class, it is defined as
$sigma(bf{y_i}) = frac{e^{bf{y_i}}}{sum_{j}{e^{bf{y_j}}}}$.
For example, in a problem with 2 class labels. Then if we have some outputs from our neural network like $y$=[3, 4] then we can get the probability of each output classes by using the softmax function on these outputs.
import numpy as np
x = [3, 4]
np.exp(x)/np.sum(np.exp(x))
[0.26894142, 0.73105858]
You will see that these are probabilities and do sum to 1.
Then we can get the class of the input by seeing which probability is higher. In this case class 2 has a probability of 73.11%, so the predicted class label, $hat{y} = 1$.
Cross-entropy
Cross-entropy is a loss function that is used for classification tasks. For binary classification it is defined as
$H(p, q) = -ylog(p) - (1-y)log(1-p)$.
Let's assume that the real class of the above example is 0, $y=0$. Then we made a mistake and you can see that
$H(p, q) = -0log(0.26894142) - (1-0)log(1-0.26894142) = 0.313$.
That is the loss that is used for backpropagation.
$endgroup$
add a comment |
$begingroup$
I think there is some confusion here. Softmax is usually an activation function which you will use in your output layer, and cross-entropy is the loss function that you will use.
Softmax
This activation function outputs the probability for each class, it is defined as
$sigma(bf{y_i}) = frac{e^{bf{y_i}}}{sum_{j}{e^{bf{y_j}}}}$.
For example, in a problem with 2 class labels. Then if we have some outputs from our neural network like $y$=[3, 4] then we can get the probability of each output classes by using the softmax function on these outputs.
import numpy as np
x = [3, 4]
np.exp(x)/np.sum(np.exp(x))
[0.26894142, 0.73105858]
You will see that these are probabilities and do sum to 1.
Then we can get the class of the input by seeing which probability is higher. In this case class 2 has a probability of 73.11%, so the predicted class label, $hat{y} = 1$.
Cross-entropy
Cross-entropy is a loss function that is used for classification tasks. For binary classification it is defined as
$H(p, q) = -ylog(p) - (1-y)log(1-p)$.
Let's assume that the real class of the above example is 0, $y=0$. Then we made a mistake and you can see that
$H(p, q) = -0log(0.26894142) - (1-0)log(1-0.26894142) = 0.313$.
That is the loss that is used for backpropagation.
$endgroup$
add a comment |
$begingroup$
I think there is some confusion here. Softmax is usually an activation function which you will use in your output layer, and cross-entropy is the loss function that you will use.
Softmax
This activation function outputs the probability for each class, it is defined as
$sigma(bf{y_i}) = frac{e^{bf{y_i}}}{sum_{j}{e^{bf{y_j}}}}$.
For example, in a problem with 2 class labels. Then if we have some outputs from our neural network like $y$=[3, 4] then we can get the probability of each output classes by using the softmax function on these outputs.
import numpy as np
x = [3, 4]
np.exp(x)/np.sum(np.exp(x))
[0.26894142, 0.73105858]
You will see that these are probabilities and do sum to 1.
Then we can get the class of the input by seeing which probability is higher. In this case class 2 has a probability of 73.11%, so the predicted class label, $hat{y} = 1$.
Cross-entropy
Cross-entropy is a loss function that is used for classification tasks. For binary classification it is defined as
$H(p, q) = -ylog(p) - (1-y)log(1-p)$.
Let's assume that the real class of the above example is 0, $y=0$. Then we made a mistake and you can see that
$H(p, q) = -0log(0.26894142) - (1-0)log(1-0.26894142) = 0.313$.
That is the loss that is used for backpropagation.
$endgroup$
I think there is some confusion here. Softmax is usually an activation function which you will use in your output layer, and cross-entropy is the loss function that you will use.
Softmax
This activation function outputs the probability for each class, it is defined as
$sigma(bf{y_i}) = frac{e^{bf{y_i}}}{sum_{j}{e^{bf{y_j}}}}$.
For example, in a problem with 2 class labels. Then if we have some outputs from our neural network like $y$=[3, 4] then we can get the probability of each output classes by using the softmax function on these outputs.
import numpy as np
x = [3, 4]
np.exp(x)/np.sum(np.exp(x))
[0.26894142, 0.73105858]
You will see that these are probabilities and do sum to 1.
Then we can get the class of the input by seeing which probability is higher. In this case class 2 has a probability of 73.11%, so the predicted class label, $hat{y} = 1$.
Cross-entropy
Cross-entropy is a loss function that is used for classification tasks. For binary classification it is defined as
$H(p, q) = -ylog(p) - (1-y)log(1-p)$.
Let's assume that the real class of the above example is 0, $y=0$. Then we made a mistake and you can see that
$H(p, q) = -0log(0.26894142) - (1-0)log(1-0.26894142) = 0.313$.
That is the loss that is used for backpropagation.
answered 20 hours ago
JahKnowsJahKnows
4,932625
4,932625
add a comment |
add a comment |
Thanks for contributing an answer to Data Science 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.
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%2fdatascience.stackexchange.com%2fquestions%2f46597%2fthe-most-used-loss-function-in-tensorflow-for-a-binary-classification%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