Skip to content

THUZeng/ai-timeseries-forecaster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI 时序预测与异常检测平台

企业级时序数据分析平台,提供高精度预测、实时异常检测和智能化数据洞察。

🎯 核心功能

时序预测

  • 多模型集成 - ARIMA、指数平滑、Prophet、LSTM等
  • 自动模型选择 - AutoML智能选择最优模型
  • 多步预测 - 支持任意预测步长
  • 置信区间 - 预测不确定性量化

异常检测

  • 多算法支持 - Z-Score、IQR、Isolation Forest、LOF
  • 实时检测 - 流式数据异常监控
  • 自适应阈值 - 动态阈值调整
  • 异常分类 - 点异常、上下文异常、集体异常

模型可解释性

  • 特征重要性 - SHAP值分析
  • 预测解释 - 单点预测归因
  • 趋势分解 - 趋势、季节性、残差分离
  • 可视化报告 - 交互式解释图表

流式处理

  • 实时预测 - 低延迟流式预测
  • 滑动窗口 - 动态窗口聚合
  • 事件触发 - 异常事件实时告警
  • 状态管理 - 流处理状态持久化

AutoML

  • 自动特征工程 - 时序特征自动提取
  • 超参优化 - 贝叶斯优化搜索
  • 模型评估 - 交叉验证与回测
  • 模型注册 - 版本化模型管理

批量处理

  • 任务调度 - 优先级任务队列
  • 并行处理 - 多线程批量预测
  • 进度跟踪 - 实时进度与ETA
  • 断点续传 - 检查点恢复

数据导出

  • 多格式支持 - JSON/CSV/HTML/Markdown
  • 报告生成 - 自动化分析报告
  • 可视化导出 - 图表嵌入报告

🏗️ 系统架构

src/
├── api/                      # FastAPI 接口层
│   ├── main.py              # 应用入口与中间件
│   ├── routes.py            # 基础路由
│   ├── timeseries_routes.py # 时序预测API
│   ├── advanced_routes.py   # 高级分析API
│   ├── explainability_routes.py # 可解释性API
│   ├── streaming_routes.py  # 流处理API
│   ├── automl_routes.py     # AutoML API
│   ├── model_routes.py      # 模型管理API
│   ├── batch_routes.py      # 批量处理API
│   └── export_routes.py     # 数据导出API
├── models/                   # 预测模型
│   ├── base_model.py        # 模型基类
│   ├── arima_model.py       # ARIMA模型
│   ├── prophet_model.py     # Prophet模型
│   └── lstm_model.py        # LSTM模型
├── anomaly/                  # 异常检测
│   └── detector.py          # 异常检测器
├── explainability/           # 可解释性
│   └── explainer.py         # 模型解释器
├── streaming/                # 流处理
│   └── stream_processor.py  # 流处理器
├── automl/                   # 自动机器学习
│   └── auto_forecaster.py   # 自动预测器
├── registry/                 # 模型注册
│   └── model_registry.py    # 模型注册表
├── batch/                    # 批量处理
│   └── batch_predictor.py   # 批量预测器
└── export/                   # 数据导出
    └── data_exporter.py     # 数据导出器

🚀 快速开始

安装依赖

pip install -r requirements.txt

启动服务

uvicorn src.api.main:app --reload --port 8001

API 文档

访问 http://localhost:8001/docs 查看交互式API文档

📡 API 示例

时序预测

import requests

response = requests.post("http://localhost:8001/api/v1/timeseries/predict", json={
    "values": [100, 120, 115, 130, 125, 140, 135, 150],
    "horizon": 5,
    "model": "auto"
})

异常检测

response = requests.post("http://localhost:8001/api/v1/timeseries/anomaly", json={
    "values": [100, 102, 98, 250, 101, 99, 103],
    "method": "zscore",
    "threshold": 3.0
})

模型解释

response = requests.post("http://localhost:8001/api/v1/explain/prediction", json={
    "values": [100, 120, 115, 130, 125],
    "prediction_index": 0
})

批量预测

# 提交任务
response = requests.post("http://localhost:8001/api/v1/batch/submit", json={
    "name": "批量预测任务",
    "predictor": "timeseries",
    "data": [{"values": [1,2,3,4,5]} for _ in range(1000)],
    "priority": "high"
})

job_id = response.json()["job_id"]

# 查询状态
status = requests.get(f"http://localhost:8001/api/v1/batch/status/{job_id}")

导出报告

response = requests.post("http://localhost:8001/api/v1/export/predictions", json={
    "predictions": [...],
    "format": "html"
})

🔧 技术栈

  • 后端框架: FastAPI
  • 数据处理: NumPy, Pandas
  • 机器学习: Scikit-learn
  • 深度学习: PyTorch (可选)
  • 可解释性: SHAP
  • 异步处理: asyncio, threading

📊 性能指标

  • 单次预测延迟: < 50ms
  • 批量处理吞吐: > 1000 items/s
  • 流处理延迟: < 100ms
  • 并发支持: > 100 QPS

📄 许可证

MIT License

About

AI 时序预测与异常检测平台 - 企业级时序数据分析

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages