简体   繁体   中英

How many neurons should be there in the output layer of a neural network for classification?

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.

There are two possible outcomes. Positive and negative.

This can be done with both 1 node or 2 nodes. If you are using one node you can define a threshold (0.5 is very common) and outputs greater than or equal that threshold will classified as positive or else negative.

And also you can use two nodes. node 0 for positive and node 1 for negative. You have to get the result related to the node with highest value out of the two outputs of the output layer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM