AditiPurohit10/AI-Security-Intelligence-Platform

GitHub: AditiPurohit10/AI-Security-Intelligence-Platform

基于 Stacking 集成模型与 SHAP 可解释性分析的网络入侵检测系统,提供实时检测与威胁情报仪表板。

Stars: 0 | Forks: 0

# AI 安全智能平台 (ASIP)
![Python](https://img.shields.io/badge/Python-3.10+-3776AB?style=for-the-badge&logo=python&logoColor=white) ![Streamlit](https://img.shields.io/badge/Streamlit-1.x-FF4B4B?style=for-the-badge&logo=streamlit&logoColor=white) ![scikit-learn](https://img.shields.io/badge/scikit--learn-1.9-F7931E?style=for-the-badge&logo=scikit-learn&logoColor=white) ![XGBoost](https://img.shields.io/badge/XGBoost-3.3-0073CF?style=for-the-badge) ![CatBoost](https://img.shields.io/badge/CatBoost-1.2-FFCA28?style=for-the-badge) ![Plotly](https://img.shields.io/badge/Plotly-5.x-3F4F75?style=for-the-badge&logo=plotly&logoColor=white) ![License](https://img.shields.io/badge/License-MIT-22C55E?style=for-the-badge) **一个基于 AI 的网络安全平台,使用 CICIDS 2017 数据集进行** **智能网络入侵检测、威胁分类和可解释的 ML 分析。** [功能](#features) · [架构](#architecture) · [结果](#results) · [安装](#installation) · [使用](#usage) · [部署](#deployment)
## 概述 **AI 安全智能平台 (ASIP)** 是一个面向生产的、端到端的机器学习网络安全解决方案。它自动化分析网络流量日志,对 12 个类别的攻击进行分类,并通过交互式 SOC(安全运营中心)仪表板展示洞察结果。 作为一个从学习到生产的项目,它结合了: - **机器学习** 用于自动化入侵检测 - **可解释 AI (SHAP)** 提供对分析人员友好的解释 - **交互式仪表板** 用于实时安全监控 - **REST API** (FastAPI) 用于与现有 SOC 工具集成 ## 功能 ### 🧠 机器学习检测 | 功能 | 详情 | |---------|---------| | **数据集** | CICIDS 2017 — 252 万条网络流记录 | | **攻击类别** | 12 个分类 (BENIGN, DDoS, DoS, Bot, PortScan 等) | | **模型** | Decision Tree, Random Forest, XGBoost, CatBoost, Stacking Ensemble | | **最高准确率** | 99.87% (XGBoost) | | **最佳 MCC** | 0.9958 (XGBoost) | ### 📊 仪表板功能 - **实时检测** — 上传 CSV 或输入流特征进行实时分类 - **模型性能** — 混淆矩阵、ROC/PR 曲线、分类报告、雷达图对比 - **威胁情报** — 攻击分布、严重性评分、趋势分析 - **可解释性** — 每次预测的 SHAP 特征重要性 ### 🔧 工程特性 - 带有 `/predict` 接口的 FastAPI REST 后端 - 使用 SQLite 记录所有检测结果 - 模块化组件架构(services/views/components) - 预计算的 ML 评估产物,加快仪表板加载速度 ## 架构 ``` AI-Security-Intelligence-Platform/ ├── dashboard/ # Streamlit SOC Dashboard │ ├── app.py # Entry point & routing │ ├── assets/ # CSS, fonts, animations, logo │ ├── components/ # Reusable UI components │ │ ├── charts.py # Benchmark Plotly charts │ │ ├── eval_charts.py # Confusion matrix, ROC, PR, radar │ │ ├── kpi.py # KPI cards │ │ └── sidebar.py # Navigation │ ├── views/ # Page-level view logic │ │ ├── home.py │ │ ├── model_performance.py # 5-tab evaluation dashboard │ │ ├── live_detection.py │ │ ├── threat_intelligence.py │ │ └── about.py │ ├── services/ # Business logic layer │ └── utils/ # Data loaders, helpers ├── src/ # Core ML library │ ├── models/ # Training pipelines │ ├── preprocessing/ # Feature engineering │ ├── explainability/ # SHAP integration │ └── api/ # FastAPI backend ├── models/ # Trained model artifacts (.pkl) ├── data/ │ ├── raw/ # Original CICIDS 2017 CSV files │ ├── processed/ # Cleaned & split datasets │ └── sample/ # Demo sample datasets ├── reports/ │ ├── metrics/ # Per-model CSVs, confusion matrices │ └── figures/ # Saved chart exports ├── scripts/ │ └── precompute_roc_pr.py # One-time ROC/PR pre-computation ├── docs/ # Architecture, report, deployment guide └── notebooks/ # Exploratory analysis ``` ## 结果 ### 模型基准测试 (CICIDS 2017 测试集 — 378,110 个样本) | 模型 | 准确率 | 平衡准确率 | MCC | Macro F1 | 预测时间 | |-------|----------|---------------|-----|----------|------------| | **XGBoost** ⭐ | **99.87%** | 93.99% | **0.9958** | 92.04% | 3.65s | | Stacking Ensemble | 99.86% | **94.27%** | 0.9954 | 91.39% | 0.48s | | Random Forest | 99.86% | 93.27% | 0.9952 | 91.77% | 4.69s | | Decision Tree | 99.85% | 93.10% | 0.9951 | 92.03% | 0.67s | | CatBoost | 98.89% | 94.04% | 0.9647 | 82.00% | 0.88s | ### 攻击类别 (12 个分类) `BENIGN` · `Bot` · `DDoS` · `DoS GoldenEye` · `DoS Hulk` · `DoS Slowhttptest` · `DoS Slowloris` · `FTP-Patator` · `Heartbleed` · `Infiltration` · `PortScan` · `Web Attack` ## 安装说明 ### 前置条件 - Python 3.10+ - Git ### 步骤 ``` # 1. 克隆仓库 git clone https://github.com/YOUR_USERNAME/AI-Security-Intelligence-Platform.git cd AI-Security-Intelligence-Platform # 2. 创建虚拟环境 python -m venv .venv .venv\Scripts\activate # Windows # source .venv/bin/activate # Linux/Mac # 3. 安装依赖 pip install -r requirements.txt # 4. (可选)预计算 ROC/PR 曲线 python scripts/precompute_roc_pr.py ``` ## 使用说明 ### 运行仪表板 ``` streamlit run dashboard/app.py ``` 在浏览器中打开 [http://localhost:8501](http://localhost:8501)。 ### 运行 API 后端(可选) ``` uvicorn src.api.main:app --reload --port 8000 ``` API 文档可在 [http://localhost:8000/docs](http://localhost:8000/docs) 查看 ### 使用示例数据进行演示 `data/sample/` 中提供了示例数据集,无需完整的 CICIDS 2017 数据集即可快速演示。 ## 部署 有关部署到的完整说明,请参阅 [docs/DEPLOYMENT.md](docs/DEPLOYMENT.md): - **Streamlit Community Cloud**(推荐 — 免费) - **Render**(基于 Docker,免费层) ## 技术栈 | 类别 | 技术 | |----------|-------------| | **语言** | Python 3.10+ | | **机器学习** | scikit-learn, XGBoost, CatBoost | | **可解释性** | SHAP | | **仪表板** | Streamlit, Plotly | | **后端 API** | FastAPI, Uvicorn | | **数据库** | SQLite | | **数据** | Pandas, NumPy | | **报告** | ReportLab (PDF) | ## 数据集 **CICIDS 2017** — Canadian Institute for Cybersecurity Intrusion Detection System 2017 - **记录数:** 总计 2,830,743 条 → 清洗后 2,520,000 条 - **特征数:** 78 个原始特征 → 48 个选定特征 - **来源:** [UNB CIC](https://www.unb.ca/cic/datasets/ids-2017.html) - **划分:** 60% 训练集 / 20% 验证集 / 20% 测试集 ## 文档 | 文档 | 描述 | |----------|-------------| | [ARCHITECTURE.md](docs/ARCHITECTURE.md) | 系统架构与数据流图 | | [PROJECT_REPORT.md](docs/PROJECT_REPORT.md) | 完整的技术项目报告 | | [DEPLOYMENT.md](docs/DEPLOYMENT.md) | 逐步部署指南 | ## 许可证 本项目采用 [MIT License](LICENSE) 授权。 ## 作者 作为结合了机器学习和网络安全技术的面向生产的学习项目而构建。 **状态:** ✅ Version 1.0 — 完成
标签:Apex, Kubernetes, Streamlit, 可解释AI, 安全运营中心, 机器学习, 网络安全, 网络映射, 访问控制, 逆向工具, 隐私保护