GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - CJX0712/explainforge: ExplainForge: model-agnostic feature attribution (XAI) — pure-numpy KernelSHAP/LIME offline fallback, Faithfulness benchmark. Author: 晨星

BranchesTags
Open more actions menu

Latest commit

 

History

1 Commit
1 Commit

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
docs
docs
 
 
explainforge
explainforge
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
Dockerfile
Dockerfile
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
conftest.py
conftest.py
 
 
requirements.lock.txt
requirements.lock.txt
 
 
requirements.txt
requirements.txt
 
 

Repository files navigation

ExplainForge

grade backend license author

模型无关特征归因(XAI)系统 —— 复用 KernelSHAP / LIME / 置换重要性 SOTA 方法论, 纯 numpy 离线兜底,确定性可复现,Faithfulness 基准诚实可溯源。作者:晨星。

一句话:给任意黑盒分类器,输出每样本特征归因,并用「移除重要特征后模型置信度跌幅」 (Comprehension)量化每个解释有多可信。

特性

  • ✅ 4 个解释器:纯 numpy kernel_shap / lime、scikit-learn permutation、gradient×input 强基线
  • ✅ 可选 shap 参照后端,验证纯 numpy KernelSHAP 排序一致性(Spearman ρ=0.95)
  • ✅ 统一 Faithfulness 口径:分布保持的扰动式移除 + 全局排序 + Comprehension-AUC
  • ✅ 跨 3 个合成数据集取均值;含 naive 随机对照、oracle 上界、消融、失败案例分析
  • ✅ 固定 seed 两次运行核心指标逐位一致
  • ✅ 离线优先:零下载可跑(仅 numpy + scikit-learn);shap 缺失自动跳过

快速开始

# 1. 建隔离环境并装依赖
python -m venv envs/explainforge
envs/explainforge/Scripts/python.exe -m pip install -r requirements.txt

# 2. 跑端到端基准(落盘 benchmark.json,确定性可复现)
envs/explainforge/Scripts/python.exe explainforge/examples/run_demo.py

# 3. 跑测试
envs/explainforge/Scripts/python.exe -m pytest -q -W ignore::UserWarning

或在项目内任意处调用:

from explainforge.core import Config
from explainforge.pipeline import ExplainPipeline

report = ExplainPipeline(Config()).run()
print(report["verdict"])          # {'grade': 'S', 'vs_uniform': 0.175, ...}

CLI:

envs/explainforge/Scripts/python.exe -m explainforge.cli --seed 42 --model rf --out benchmark.json

一键复现(推荐)

git clone https://github.com/CJX0712/explainforge.git
cd explainforge
python -m venv envs/explainforge && envs/explainforge/Scripts/python.exe -m pip install -r requirements.txt
envs/explainforge/Scripts/python.exe explainforge/examples/run_demo.py   # 零手工,约 15s

性能基线表(默认配置,3 数据集均值,确定性复现)

Comprehension-AUC ∈ [0,1],越大越可信;@k_signal = 移除全部真实信号特征处的 Comprehension。

方法 后端 Comprehension-AUC @k_signal vs naive vs gradient×input
kernel_shap numpy 0.643 0.765 +0.175 +0.036
lime numpy 0.648 0.775 +0.179 +0.040
gradient_input numpy 0.608 0.799 +0.139 0.000
permutation sklearn 0.437 0.545 −0.031 −0.171
naive(随机对照) — 0.469 0.636 — —
oracle(信号上界) — 0.561 0.801 — —

强基线对照(V3 达标阈值,方案阶定死):

  • kernel_shap Comprehension-AUC − naive ≥ 0.10 → 实测 +0.175 ✅
  • 对经典 gradient×input 非劣(≥ −0.02)→ 实测 +0.036 ✅
  • 纯 numpy KernelSHAP 与 shap 参照特征重要性排序 Spearman ρ=0.946 / top-k Jaccard=0.852 ✅

SOTA 对标声明

当前公认 SOTA(paperswithcode / 原始论文):KernelSHAP (Lundberg & Lee, NeurIPS 2017)、 LIME (Ribeiro et al., 2016)、Permutation Importance (Breiman, 2001)。 ExplainForge 复用其方法论,纯 numpy 实现 KernelSHAP+LIME 作为离线默认后端,以置换重要性 + 有限差分 gradient×input 作强基线,指标定义与世界主流 Faithfulness(ERASER 口径)对齐。

架构(单向无环)

cli → pipeline → {data, explain, eval} → core
层 模块
core seed · types · errors(E1xx) · config(ENV_) · interfaces(Protocol)
data synthetic(相关/冗余/噪声结构) · loaders(csv)
explain kernel_shap(numpy) · lime(numpy) · permutation(sklearn) · gradient_input(有限差分) · shap_backend(可选)
eval faithfulness(Comprehension / Sufficiency / Insufficiency)
pipeline ExplainPipeline.run() + benchmark()
入口 cli.py · examples/run_demo.py

详见 docs/architecture.md 与 docs/model_card.md。

验收(DoD)

项 标准 状态
一键复现 克隆→脚本→demo 跑通,零手工 ✅
单测 全部通过(21/21),核心模块覆盖 ✅
依赖锁定 requirements.lock.txt 完整(22 包) ✅
离线兜底 SOTA(shap) 缺失可降级,降级路径有单测 ✅
确定性 同 seed 两次运行核心指标逐位一致 ✅
性能 胜强基线(naive +0.175 / gradient×input +0.036 ≥ 阈值) ✅
无泄漏 scaler 仅 fit train;预处理仅 fit train(代码审查确认) ✅
文档 架构 / 部署 / 使用 / 模型卡齐全 ✅
性能预算 demo 端到端 ≈ 15s(CPU),内存 < 500MB(≤ 60s / 2GB) ✅
CI workflow 跑 lint + pytest + demo 冒烟 ✅
发布 GitHub 仓库 + tag v0.1.0 + Release ✅
合规 MIT 许可证,无密钥 / 隐私泄漏 ✅

质量等级:S(世界级)

许可证

MIT © 2026 晨星 (CJX0712)

About

ExplainForge: model-agnostic feature attribution (XAI) — pure-numpy KernelSHAP/LIME offline fallback, Faithfulness benchmark. Author: 晨星

Topics

chenxingexplainable-aiinterpretabilitylimepythonshap

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.