# zhanghongqi1/diabetes-risk-prediction-platform architecture

> Architecture diagram of the GitHub repository zhanghongqi1/diabetes-risk-prediction-platform, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zhanghongqi1/diabetes-risk-prediction-platform
- Repository: https://github.com/zhanghongqi1/diabetes-risk-prediction-platform

## Overview

这是一个基于 Pima Indians Diabetes 数据集的糖尿病风险预测与健康数据分析平台。主流程是导入原始数据、训练并选择模型、由 Flask 提供单例或 CSV/Excel 批量预测、将预测留痕到 MySQL，再向页面返回风险结果。训练阶段还包含 OOF 阈值调优、模型对比、特征重要性与相关性热力图；稳定性复训是独立验证分支。README 记录了智能体部署能力，但没有对应运行时代码路径，因此不纳入仓库运行链路。关系依据 README 与所采样源码；未采样的页面调用细节仅按文档接口概述。

Main entry points: [`web/app.py`](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/web/app.py) (Flask 应用), [`scripts/03_train_models.py`](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/scripts/03_train_models.py) (模型训练选型), [`scripts/init_db.sql`](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/scripts/init_db.sql) (MySQL 数据库), [`web/index.html`](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/web/index.html) (风险仪表盘)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["数据准备"]
  node_rawdata["原始数据"]
  node_import["数据导入清洗<br/>[02_import_data.py]"]
  node_db[("MySQL 数据库<br/>[init_db.sql]")]
  node_processed["清洗预览数据"]
  node_record[("预测记录<br/>[init_db.sql]")]
end

subgraph group_modeling["模型训练"]
  node_training["模型训练选型<br/>[03_train_models.py]"]
  node_artifacts["模型与指标<br/>[selected_model.pkl]"]
  node_meta["模型元数据<br/>[model_meta.json]"]
  node_importance["特征重要性"]
  node_heatmap["相关性热力图"]
  node_stability["稳定性验证"]
  node_stabilityout["稳定性结果<br/>[stability.json]"]
end

subgraph group_service["预测服务"]
  node_webapp["Flask 应用<br/>[app.py]"]
  node_validation["输入校验配置<br/>[db_config.py]"]
end

subgraph group_presentation["结果呈现"]
  node_webpage["风险仪表盘<br/>[index.html]"]
end

node_user(("使用者"))
node_batchfile["批量文件"]

node_rawdata -->|"读取"| node_import
node_import -->|"写入原始及清洗数据"| node_db
node_import -->|"导出预览"| node_processed
node_training -->|"读取原始数据"| node_db
node_training -->|"导出模型"| node_artifacts
node_training -->|"写入指标阈值"| node_meta
node_training -->|"导出重要性"| node_importance
node_training -->|"生成图表"| node_heatmap
node_training -->|"写入模型指标"| node_db
node_stability -->|"读取原始数据"| node_db
node_stability -->|"读取超参数阈值"| node_meta
node_stability -->|"保存结果"| node_stabilityout
node_user -->|"访问"| node_webpage
node_webpage -->|"调用预测接口"| node_webapp
node_user -->|"提供文件"| node_batchfile
node_batchfile -->|"上传批量文件"| node_webapp
node_webapp -->|"使用校验规则"| node_validation
node_webapp -->|"加载并推理"| node_artifacts
node_webapp -->|"读取部署配置"| node_meta
node_webapp -->|"读取特征贡献度"| node_importance
node_webapp -->|"查询健康及历史"| node_db
node_webapp -->|"保存预测记录"| node_record
node_webapp -->|"返回结果与指标"| node_webpage
node_heatmap -->|"页面展示"| node_webpage

click node_rawdata "https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/data/raw/pima-indians-diabetes.data.csv"
click node_import "https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/scripts/02_import_data.py"
click node_db "https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/scripts/init_db.sql"
click node_processed "https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/data/processed/pima-indians-diabetes.clean.csv"
click node_training "https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/scripts/03_train_models.py"
click node_artifacts "https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/models/selected_model.pkl"
click node_meta "https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/models/model_meta.json"
click node_importance "https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/models/feature_importance.csv"
click node_heatmap "https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/tree/main/web/static/img"
click node_stability "https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/scripts/04_stability_check.py"
click node_stabilityout "https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/models/stability.json"
click node_webapp "https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/web/app.py"
click node_validation "https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/scripts/db_config.py"
click node_webpage "https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/web/index.html"
click node_record "https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/scripts/init_db.sql"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_rawdata,node_import,node_db,node_processed,node_record toneBlue
class node_training,node_artifacts,node_meta,node_importance,node_heatmap,node_stability,node_stabilityout toneAmber
class node_webapp,node_validation toneMint
class node_webpage toneRose
class node_user,node_batchfile toneIndigo
```

## Components

### 数据准备

- [原始数据](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/data/raw/pima-indians-diabetes.data.csv): `data/raw/pima-indians-diabetes.data.csv`
- [数据导入清洗](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/scripts/02_import_data.py): `scripts/02_import_data.py`
- [MySQL 数据库](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/scripts/init_db.sql): `scripts/init_db.sql`
- [清洗预览数据](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/data/processed/pima-indians-diabetes.clean.csv): `data/processed/pima-indians-diabetes.clean.csv`
- [预测记录](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/scripts/init_db.sql): `scripts/init_db.sql`

### 模型训练

- [模型训练选型](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/scripts/03_train_models.py): `scripts/03_train_models.py`
- [模型与指标](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/models/selected_model.pkl): `models/selected_model.pkl`
- [模型元数据](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/models/model_meta.json): `models/model_meta.json`
- [特征重要性](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/models/feature_importance.csv): `models/feature_importance.csv`
- [相关性热力图](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/tree/main/web/static/img): `web/static/img`
- [稳定性验证](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/scripts/04_stability_check.py): `scripts/04_stability_check.py`
- [稳定性结果](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/models/stability.json): `models/stability.json`

### 预测服务

- [Flask 应用](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/web/app.py): `web/app.py`
- [输入校验配置](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/scripts/db_config.py): `scripts/db_config.py`

### 结果呈现

- [风险仪表盘](https://github.com/zhanghongqi1/diabetes-risk-prediction-platform/blob/main/web/index.html): `web/index.html`

### Other components

- **使用者**
- **批量文件**

## Connections

- 原始数据 → 数据导入清洗: 读取
- 数据导入清洗 → MySQL 数据库: 写入原始及清洗数据
- 数据导入清洗 → 清洗预览数据: 导出预览
- 模型训练选型 → MySQL 数据库: 读取原始数据
- 模型训练选型 → 模型与指标: 导出模型
- 模型训练选型 → 模型元数据: 写入指标阈值
- 模型训练选型 → 特征重要性: 导出重要性
- 模型训练选型 → 相关性热力图: 生成图表
- 模型训练选型 → MySQL 数据库: 写入模型指标
- 稳定性验证 → MySQL 数据库: 读取原始数据
- 稳定性验证 → 模型元数据: 读取超参数阈值
- 稳定性验证 → 稳定性结果: 保存结果
- 使用者 → 风险仪表盘: 访问
- 风险仪表盘 → Flask 应用: 调用预测接口
- 使用者 → 批量文件: 提供文件
- 批量文件 → Flask 应用: 上传批量文件
- Flask 应用 → 输入校验配置: 使用校验规则
- Flask 应用 → 模型与指标: 加载并推理
- Flask 应用 → 模型元数据: 读取部署配置
- Flask 应用 → 特征重要性: 读取特征贡献度
- Flask 应用 → MySQL 数据库: 查询健康及历史
- Flask 应用 → 预测记录: 保存预测记录
- Flask 应用 → 风险仪表盘: 返回结果与指标
- 相关性热力图 → 风险仪表盘: 页面展示
