i use this code with keras for feature laerning and now i wantٍ do classification ,i dont know how add softmax layer to my auto encoder,please help me
Autoencoders are not meant for classification.
They just condense data in an encoded format so you can use this data later for other things (one of the other things may be classification, but it's really pointless to create an autoencoder for this unless you have more use for the data than just classification)
To create a classificator from your input data, just make a model that ends in the number of classes you want.
For "normal" and "attack" (just two classes), you can end the model in one class and make 0 be normal
and 1 be attack
.
input_tensor = Input(shape=(input_size,))
output_tensor = Dense(40, activation="relu", activity_regularizer=regularizers.l1(10e-5))(input_tensor)
output_tensor= Dense(30, activation="relu")(output_tensor)
output_tensor = Dense(20, activation="relu")(output_tensor)
output_tensor= Dense(10, activation="relu")(output_tensor)
output_tensor= Dense(5, activation="relu")(output_tensor)
output_tensor= Dense(3, activation="relu")(output_tensor)
output_tensor= Dense(1,activation='sigmoid')(output_tensor)
model = Model(input_tensor,output_tensor)
I used 1 output (Dense(1)) that I want to be 0 (normal) or 1 (attack). The 'sigmoid' activation is important to keep the results inside this range or 0 and 1.
Now you just need to make sure that your y_true
data is an array shaped as (records,)
or (records,1)
, depending on the model.