### Creating Auto-encoder # Instantiate a sequential model autoencoder = Sequential() # Add a hidden layer of 4 neurons and an input layer of 100 autoencoder.add(Dense(4, input_shape=(100,), activation='relu')) # The hidden layer with 4 neurons will strictly compress the information to learn # Add an output layer of 100 neurons autoencoder.add(Dense(100, activation='sigmoid')) # Compile your model with the appropiate loss autoencoder.compile(optimizer='adam', loss='binary_crossentropy') ### A separate model to encode inputs # Building a separate model to encode inputs encoder = Sequential() encoder.add(autoencoder.layers[0]) # Only add the first hidden layer with 4 neurons # This will return what the four hidden layer neuron sees as features for the test data encoder.predict(X_test)for l1,l2 in zip(full_model.layers[:19],autoencoder.layers[0:19]): l1.set_weights(l2.get_weights())