πŸ“Š 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.

Pub Version License: MIT


πŸš€ 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

  • x Z-Score detector
  • IQR-based anomaly detection
  • Local Outlier Factor (LOF)
  • DBSCAN
  • Visual anomaly plotting (with Flutter)

πŸ“ƒ License

MIT Β© 2025 Mehmet Γ‡elik

Contributions are welcome! PRs & feedback appreciated.