First, we import pyod, our Python object detection library. Then we import numpy for data manipulation and pickle for saving our model. Next, we use numpy to load our data. Then we train our model and get the prediction scores. Finally, we save our model.
An autoencoder takes data as input and reduces the number of nodes through a smaller hidden layer that forces it to reduce the dimensionality. The target output for an autoencoder is the input. This allows us to use machine learning to train a model on what is non-anomalous. We can then determine how far a value falls away from the trained model. These values would be anomalous. The following diagram shows conceptually how data is coded into a set of inputs. Then, its dimensionality is reduced in the hidden layer and, finally, is outputted into a larger set of outputs: