I have created a deep neural network for the classification of breast lesions. There are two possible outcomes. The lesion is either benign or malignant. My output layer is defined as below:
model.add(Dense(2, activation='sigmoid'))
My query is that should the number of layers in the output layer be 2 or 1? I have read a few articles where in some cases, the number of neurons in the output layer is the same as the number of class labels. Whereas in some blogs, the number of neurons should be 1 for a 2 class label(binary) problem. Any suggestions would be appreciated.
If you're using sigmoid, you want to use 1. If you use 2, use softmax. You can use either, but 1 is sufficient for a binary classification (usually you'd say if the value is smaller than 0.5 then it is class A, and if it is greater than 0.5 it is class B). Softmax on the other hand models each unit as a probability.
Notably as well, if you are using 2 units, you want to use categorical cross-entropy loss.