π ml_anomaly_detector
A simple and extensible Dart package for anomaly detection using classical algorithms like Z-Score, with support for pluggable strategies and detailed result reporting.
π Features
- β Z-Score based anomaly detection
- π¦ Designed for extensibility (LOF, IQR, DBSCAN coming soon)
- π Returns detailed results: value, score, confidence, explanation
- π Compatible with time-series or single-point anomaly detection
- π‘ Easy to use, production-ready
π§ Example
import 'package:ml_anomaly_detector/ml_anomaly_detector.dart';
void main() {
final data = [1.0, 1.1, 0.9, 1.2, 10.0];
final detector = ZScoreDetector(threshold: 2.0);
final results = detector.detect(data);
for (var result in results) {
print(
'Value: \${result.value}, Score: \${result.score.toStringAsFixed(2)}, '
'Anomaly: \${result.isAnomaly}');
}
}
π¦ Installation
Add the following line to your pubspec.yaml:
dependencies:
ml_anomaly_detector: ^1.0.0
Then run:
dart pub get
π API Overview
ZScoreDetector
ZScoreDetector({
double threshold = 3.0,
String algorithmName = 'z_score',
});
AnomalyResult
| Field | Type | Description |
|---|---|---|
value |
double |
Original input value |
score |
double |
Anomaly score (Z-score, etc.) |
isAnomaly |
bool |
Whether it's an anomaly |
index |
int? |
Optional index in dataset |
confidence |
double? |
Confidence level (0.0 to 1.0) |
algorithm |
String? |
Name of algorithm used |
explanation |
String? |
Human-readable decision explanation |
π§ͺ Tests
Run unit tests using:
dart test
π Roadmap
xZ-Score detectorIQR-based anomaly detectionLocal Outlier Factor (LOF)DBSCANVisual anomaly plotting (with Flutter)
π License
MIT Β© 2025 Mehmet Γelik
Contributions are welcome! PRs & feedback appreciated.