Spotting outliers using autoencoders
Another great application of autoencoders is outlier detection. The idea behind this use case is that the autoencoder will learn an encoding with a very small error for the most common classes in a dataset, while its ability to reproduce scarcely represented categories (outliers) will be much more error-prone.
With this premise in mind, in this recipe, we'll rely on a convolutional autoencoder to detect outliers in a subsample of Fashion-MNIST
.
Let's begin!
Getting ready
To install OpenCV
, use the following pip
command:
$> pip install opencv-contrib-python
We'll rely on TensorFlow's built-in convenience functions to load the Fashion-MNIST
dataset.
How to do it…
Follow these steps to complete this recipe:
- Import the required packages:
import cv2 import numpy as np from sklearn.model_selection import train_test_split from tensorflow.keras import Model from tensorflow.keras.datasets import...