Sigmoid as a last layer in LSTM

1k Views Asked by At

I have a classification (Keras) with LSTM for a dataset with 4 attributes labeled into 2 classes (safe and unsafe). with put the sigmoid in the last layer I got a better accuracy of 98% rather than softmax. My question is that:
1 )If I use Softmax in the last layer: in Softmax based on the 2 neurons as output at the end in other code, I can compare the score and say the data belong to which. For example score_safe= 1.2945 and score_unsafe= -9.0 then I can say this row of dataset belongs to the safe class. 2)If I use Sigmid in the last layer: Then I had to put just a neuron as up output and how can I compare the scores and how can say this row of datasets belongs to which class?

model = Sequential()
model.add(LSTM(256, input_shape=(x_train.shape[1:]), activation='tanh', return_sequences=True))
#model.add(BatchNormalization())
model.add(Dense(128, activation='tanh'))
#model.add(BatchNormalization())
model.add(Dense(128, activation='tanh'))
model.add(Dense(1, activation='sigmoid'))
1

There are 1 best solutions below

0
On

The output of a sigmoid is a single float between 0. and 1.

Typically, it is set such that if the output is below 0.5 the model is classifying as the first class (whichever class is represented as a 0 in your dataset). If the output is above 0.5 the model is classifying as the second class (represented as a 1 in your dataset).

The 0.5 threshold can be varied to introduce a bias toward one or the other class.