danieleteti/delphi-anomalies-detectors
GitHub: danieleteti/delphi-anomalies-detectors
一个使用统计与机器学习方法在业务数据中检测异常的 Delphi 库,解决实时与批量场景下的监控与欺诈识别问题。
Stars: 27 | Forks: 4
# Delphi 异常检测库
[](https://www.embarcadero.com/products/delphi)
[](LICENSE)
[](Tests/)
一个用于使用统计和机器学习方法检测业务数据异常的综合库。适用于欺诈检测、系统监控、数据验证和质量控制。
**完整的文档、示例和 API 参考请访问:[danieleteti.it/delphianomalydetection](https://www.danieleteti.it/delphianomalydetection)**
## 功能
- **6 种检测算法** - 三西格玛、滑动窗口、EMA、自适应、孤立森林、DBSCAN
- **生产就绪** - 线程安全、内存高效、经过充分测试
- **实时与批处理** - 流式数据和历史分析
- **易于集成** - 单一单元,无外部依赖
- **性能监控** - 内置指标与基准测试
- **超参数调优** - 网格/随机搜索与交叉验证
## 算法
| 算法 | 适用场景 | 速度 |
|-----------|----------|-------|
| **三西格玛** | 质量控制、基线分析 | 快 |
| **滑动窗口** | 实时监控、看板 | 中等 |
| **EMA** | 财务数据、趋势模式 | 非常快 |
| **自适应** | 演化的模式、学习系统 | 快 |
| **孤立森林** | 欺诈检测、多维度 | 中等 |
| **DBSCAN/LOF** | 基于聚类的异常 | 慢 |
## 快速开始
```
uses
AnomalyDetection.Types,
AnomalyDetection.ThreeSigma,
AnomalyDetection.Factory;
var
Detector: IAnomalyDetector;
Result: TAnomalyResult;
begin
// Create detector
Detector := Factory.CreateDetector(adtThreeSigma, 'QualityControl');
// Add data and build
Detector.AddValues([100, 105, 98, 102, 107, 99, 103, 101]);
Detector.Build;
// Detect anomaly
Result := Detector.Detect(150);
if Result.IsAnomaly then
WriteLn('Anomaly detected! Z-score: ', Result.ZScore:0:2);
end;
```
## 实时监控
```
uses AnomalyDetection.SlidingWindow;
var
Detector: TSlidingWindowDetector;
begin
Detector := TSlidingWindowDetector.Create(100); // 100-value window
try
while HasIncomingData do
begin
Value := GetNextReading;
if Detector.IsAnomaly(Value) then
TriggerAlert('Spike detected: ' + Value.ToString);
Detector.AddValue(Value);
end;
finally
Detector.Free;
end;
end;
```
## 欺诈检测(多维)
```
uses AnomalyDetection.IsolationForest;
var
Detector: TIsolationForestDetector;
begin
Detector := TIsolationForestDetector.Create(100, 256, 5); // 100 trees, 5 features
try
// Train on normal transactions
for Transaction in NormalTransactions do
Detector.AddTrainingData([Amount, Hour, Day, Category, Age]);
Detector.Train;
// Detect fraud
Result := Detector.DetectMultiDimensional([5000, 3, 2, 5, 35]);
if Result.IsAnomaly then
FlagForReview('Suspicious transaction');
finally
Detector.Free;
end;
end;
```
## 工厂模式
```
uses AnomalyDetection.Factory;
// Pre-configured detectors for common use cases
WebDetector := Factory.CreateForWebTrafficMonitoring;
FinanceDetector := Factory.CreateForFinancialData;
IoTDetector := Factory.CreateForIoTSensors;
FraudDetector := Factory.CreateForHighDimensionalData;
```
## 文档
**完整文档包含所有算法、示例和调整指南:**
**[danieleteti.it/delphianomalydetection](https://www.danieleteti.it/delphianomalydetection)**
## 安装
1. 从 GitHub 下载或克隆
2. 将 `src` 文件夹添加到库路径
3. 将合适的单元添加到项目中
## 要求
- Delphi 10.3 Rio 或更高版本
- 无外部依赖
## 许可证
Apache 2.0 - 适用于商业和个人使用。
## 专业支持
- **培训与咨询**: [Bit Time Professionals](https://www.bittimeprofessionals.com)
- **邮箱**: [professionals@bittime.it](mailto:professionals@bittime.it)
## 支持
- **文档**: [danieleteti.it/delphianomalydetection](https://www.danieleteti.it/delphianomalydetection)
- **问题反馈**: [GitHub Issues](https://github.com/danieleteti/delphi-anomalies-detectors/issues)
- **社区**: [Facebook Group](https://www.facebook.com/groups/delphimvcframework)
标签:Apex, DBSCAN, Delphi 异常检测, EMA, LOF, 三倍标准差, 业务数据, 交叉验证, 企业级应用, 内存高效, 历史分析, 实时检测, 异常检测, 性能监控, 批处理, 数据质量, 数据验证, 机器学习, 欺诈检测, 流数据, 滑动窗口, 生产级, 线程安全, 统计分析, 网格搜索, 自适应算法, 质量控制, 超参数调优, 随机搜索, 隔离森林, 集成单元