Issue
In most of the articles I encountered that dealt with binary classification, I tended to see 2 main types of outputs:
Dense(2, activation = "softmax")
OR
Dense(1, activation = "sigmoid")
What are the differences between having Dense(2, activation = "softmax") or Dense(1, activation = "sigmoid") as an output layer for binary classification ?
Specifically:
Firstly, is there a difference in performance ?
Lastly, one trained, is there a difference in use?
Solution
There is essentially no difference between the two as you describe in this question. However, "softmax" can also be applied to multi-class classification, whereas "sigmoid" is only for binary classification.
"sigmoid" predicts a value between 0 and 1. Graphically it looks like this:

Softmax predicts a value between 0 and 1 for each output node, all outputs normalized so that they sum to 1. For example, for 3-class classification you could get the output 0.1, 0.5, 0.4. Here the second class is the prediction, as it has the largest value. For binary classification, the output of both nodes must sum to 1. The value output by each node is the confidence that it predicts that class. For example, if the output is 0.1, 0.9, then class 0 is predicted with 0.1 likelihood (i.e. not very likely) and class 1 is predicted with 0.9 likelihood, so you can be pretty certain that it is class 1.
The only difference between these two approaches will be how you use the output of your neural network. With "sigmoid" your output will be a single value per example. e.g. [0.1, 0.6, 0.8] for three different examples corresponds to example 1 being predicted as class 0, example 2 being predicted class 1 (but not very certain) and example 3 being predicted class 1 (with higher certainty).
With "softmax", for each example you will predict two values, the liklihood of class 0 and class 1 for that example, e.g. [[0.2, 0.8], [0.6, 0.4]], meaning that example 1 was predicted to be class 1 with 0.8 likelihood and example two was predicted class 0 with 0.6 likelihood.
Answered By - Jason Dominguez Answer Checked By - Cary Denson (Python.Easybugfix Admin)
Post a Comment
Post a Comment