Overview
Anomaly detection identifies unusual patterns, outliers, or deviations in time-series data. Samay supports anomaly detection through reconstruction-based methods, where the model learns normal patterns and flags points with high reconstruction error as anomalies.Models Supporting Anomaly Detection
| Model | Approach | Zero-Shot | Fine-Tuning |
|---|---|---|---|
| MOMENT | Reconstruction | ✅ | ✅ |
| LPTM | Reconstruction | ✅ | ✅ |
Step-by-Step Workflow
Prepare anomaly dataset
Load data with known anomaly boundaries:
The
boundaries parameter defines:train_end: Where normal data endsanomaly_start: Where anomalies beginanomaly_end: Where anomalies end (0 = end of file)
Real Examples
MOMENT Zero-Shot Anomaly Detection
Frommoment_anomaly_detection.ipynb:
LPTM Anomaly Benchmark
Fromlptm_anomaly_benchmark.ipynb, process multiple anomaly files:
saved_anomalies/anomalies_log.csv.
Advanced Techniques
Fine-Tuning for Domain-Specific Anomalies
Improve detection on your specific data:Threshold Selection
Choose optimal threshold for anomaly classification:Multivariate Anomaly Detection
Detect anomalies across multiple time-series channels:Evaluation Metrics
Adjusted Best F1 Score
Accounts for point-wise and window-wise detection:Precision, Recall, and F1
Area Under ROC Curve (AUC)
Use Cases
Manufacturing
Detect equipment failures and quality defects in sensor data
IT Operations
Identify server failures, network anomalies, and security breaches
Finance
Detect fraudulent transactions and market anomalies
Healthcare
Monitor patient vitals and detect abnormal patterns in ECG/EEG data
Tips for Better Detection
Use sufficient context
Use sufficient context
Ensure context length covers typical patterns. For periodic data, use at least 2-3 periods.
Handle class imbalance
Handle class imbalance
Anomalies are rare. Use metrics like F1 score instead of accuracy. Consider stratified sampling during training.
Tune the stride parameter
Tune the stride parameter
Smaller stride (e.g., 512) provides more granular detection but increases computation. Larger stride is faster but may miss short anomalies.
Combine multiple scores
Combine multiple scores
Use ensemble of reconstruction error, prediction error, and statistical measures for robust detection.
Domain knowledge matters
Domain knowledge matters
Incorporate domain-specific thresholds and validation rules. Not all statistical anomalies are operationally significant.
Next Steps
- Time-series with missing values? See Imputation Guide
- Classification task? Check Classification Guide
- Model too large? Learn about Quantization