This project implements anomaly detection on heartrate time-series data using the Matrix Profile technique, powered by the STUMPY library. It reads input data, computes matrix profiles, identifies anomalies, visualizes results, and exports findings for further analysis.
- Matrix Profile Computation: Detects unusual patterns in time-series data using STUMPY.
- Anomaly Detection: Identifies timestamps where anomalies occur based on a configurable threshold.
- Data Normalization: Optionally normalizes data to improve detection consistency.
- Interactive Plotting: Visualizes time series and anomalies with Plotly.
- Results Export: Saves computed profiles, scores, and anomalies to a pickle file.
- Python 3.8+
- Required packages:
numpypandasstumpyplotlypickle(standard library)functools(standard library)datetime(standard library)
Install dependencies using:
pip install numpy pandas stumpy plotly- Place your heartrate data as a CSV file in the
datadirectory (default expectsheartrate_personal_reduced.csv). - Run the script:
python src/matrix-profiling.py- The script will:
- Read the input data
- Compute matrix profiles
- Detect anomalies using the specified threshold
- Display plots for each column
- Export results to
mp_exported.pkl
You can adjust parameters directly in the script:
window_size: Sliding window size for matrix profile computationsmooth_n: Rolling window size for smoothingnormalize_data: Boolean to enable/disable normalizationplot_results: Boolean to enable/disable plottingthreshold: Float to set the anomaly detection threshold
- Printed Output: Displays top scores and detected anomalies.
- Exported Pickle File: Contains:
mp_dists: Matrix profile distances per columndf_scores: Scores and rankingsanomalies: DataFrame with detected anomalies
The script outputs something like:
score rank
heartrate 0.12 1.0
timestamp column value index mp_score
0 2023-05-01 heartrate 85.0 150 0.95
1 2023-05-02 heartrate 120.0 320 1.10
This project is provided as-is for research and educational purposes.
