A simple end-to-end example of detecting anomalies in a univariate time series using a PyTorch LSTM autoencoder and visualizing results in a Streamlit dashboard.
- Synthetic data generator: builds a noisy sinusoidal series with random “spikes”.
- LSTM Autoencoder: learns to reconstruct normal sequences, flags outliers by reconstruction error.
- Thresholding: computes a data-driven anomaly threshold (mean + 3·std of train errors).
- CLI scripts:
train.py
— generate data & train the modeldetect.py
— compute reconstruction errors & label anomalies
- Streamlit dashboard: interactive charts of original series, reconstruction error, and anomaly markers.
- Dockerized: one-step build & launch.
- Python 3.8+
- (Optional) Docker & Docker Engine
-
Clone the repo
git clone https://github.com/ion-linti/ts-anomaly-detector.git cd ts-anomaly-detector
-
Create & activate a virtual environment
python3 -m venv venv source venv/bin/activate # Linux/macOS # .\venv\Scripts\activate # Windows PowerShell
-
Install dependencies
pip install --upgrade pip pip install -r requirements.txt
python train.py
python detect.py
streamlit run app.py
Open http://localhost:8501 and click to refresh plots.
docker build -t ts-anomaly-detector .
docker run --rm -p 8501:8501 ts-anomaly-detector
Fork → branch → PR → merge.
MIT License