Creating a VAE for time series anomaly detection
Building on the foundation laid in the previous recipe, we now turn our attention to VAEs, a more sophisticated and probabilistic approach to anomaly detection in time series data. Unlike traditional AEs, VAEs introduce a probabilistic interpretation, making them more adept at handling inherent uncertainties in real-world data.
Getting ready
This code in this recipe is based on PyOD. We also use the same dataset as in the previous recipe:
N_LAGS = 144 series = dataset['y']
Now, let’s see how to create a VAE for time series anomaly detection.
How to do it…
We begin by preparing our dataset, as in the previous recipe:
- The dataset is first transformed using a sliding window, a technique that helps the model understand temporal dependencies within the time series:
import pandas as pd from sklearn.preprocessing import StandardScaler import numpy as np input_data = [] for i in range(N_LAGS, series...