Imagine having over thousands of input features in your dataset and you've to train them all..well, sometimes we wish we could compress the dataset to less number of features. Right? well, we can do that using a special type of Neural Network called Auto-encoders. So, let's have a brief introduction to Auto-encoders.
Auto-encoders are a branch of neural networks which basically compresses the information of the input variables into a reduced dimensional space and then it recreate the input data set to train it all over again.
Auto-encoder consists of 3 main components
Encoder: An encoder is a feed-forward, fully connected neural network that compresses the input into a latent space representation and encodes the input image as a compressed representation in a reduced dimension, and produces code. The lower the size of the code, the higher the compression.
Code: This part of the network contains the reduced representation of the input that is fed into the decoder.
Decoder: A decoder is also a feed-forward neural network that is similar to an encoder but the representation is the exact mirror image of the encoder. The decoder reconstructs the input back to the original dimensions from the code.
Note: The dimensions of both input and output must be the same.
first, the input passes through the encoder, which is a fully-connected ANN, to produce the code. The decoder, which has the similar ANN structure, then produces the output only using the code. The goal is to get an output identical with the input. Note that the decoder architecture is the mirror image of the encoder. This is not a requirement but it's typically the case. The only requirement is the dimensionality of the input and output needs to be the same. Anything in the middle can be played with.
Auto Encoders can have many different hyperparameters but the very important ones are:
Let's look at how we can do dimensionality reduction using auto-encoders. Let's take a dataset that has 12 features and 8664 columns. Now our goal is to compress the dataset into 6 features.
Original dataset with 12 features
Let us scale the data so that all our data points lie in the same range
dataset after scaling
Let's build an auto-encoder with a code size of 6.
let's train the model
autoencoder model summary
Compressed version of the original (12 features) dataset with 6 features
We can see that output from the encoder which compressed our dataset into 6 features.
Input Vs. Reconstruction plot. The red shaded portion shows the error between Original vs Reconstructed data.