pypcfx-glitch/risk-rule-design
Rule mining for data risk control, distilled from the ideas of the "100-Day Risk Control Expert" course
编辑导读Editor's Brief
## 核心特性
- 该插件在指定的 X/y 数据集上运行风险规则工作流,完成数据质量检查、单规则挖掘、并行规则集组合和 HTML 报告生成。
- 它注册三个工具:rrd_profiling 用于确认特征并移除 ID、序列号、常量、近唯一或高缺失列;rrd_mining 用于单规则评估和最优规则集组合;rrd_report 用于基于挖掘快照重新生成或调整报告。
- 它提供一个名为 risk-rule-design 的专家技能,包含角色定义、工作流步骤、评估标准和报告结构,供模型或用户调用。
- 挖掘步骤可输出最优组合、HTML 报告和快照,报告步骤可复用该快照重新生成报告。
- 生成的 HTML 报告包含数据集质量检查、单变量规则统计、组合规则指标、全组合排名、散点图和精确率-召回率视图、候选规则池以及附录配置详情。
## 使用场景
- 风控策略人员可以在准备好的样本数据上,用规则挖掘流程替代人工策略调整。
- 数据分析人员可以在为目标变量选择规则组合前,检查特征质量和候选规则。
- 报告使用者可以直接在浏览器中打开自包含 HTML 文件,无需外部资源。
## 技术细节
- 该实现采用 MIT 许可,是纯 JavaScript ESM,零构建步骤且零外部依赖。
- 该包包含一个用于注册工具和技能的入口文件、一个用于 CSV 解析、质量检查、单规则评估和组合搜索的引擎文件,以及一个用于生成内联 CSS 和 SVG 的自包含 HTML 报告文件。
- 安装可以通过 dsh plugin --profile web install 使用 npm 包 dsh-plugin-risk-rule-design,并自动将 bundle 注册到 profile。
- 通过 GitHub 安装会添加依赖,但需要手动将包名追加到 profile bundle 列表,并重启 dsh web。
## 注意事项
- README 说明该插件仍在完善中,使用过程中可能存在问题。
- 用户调用该技能时必须提供数据集路径、指定目标字段,并标识要排除的字段。
- GitHub 安装方式不会自动注册 bundle,因此需要手动配置 profile。
## Core Features
- The plugin runs a risk-rule workflow on a specified X/y dataset through data quality checking, single-rule mining, parallel rule-set combination, and HTML report generation.
- It registers three tools: rrd_profiling for confirming features and removing ID, serial number, constant, near-unique, or high-missing columns, rrd_mining for single-rule evaluation and optimal rule-set combination, and rrd_report for regenerating or adjusting a report from a mining snapshot.
- It provides one expert skill named risk-rule-design that contains role definitions, workflow steps, evaluation criteria, and report structure for model or user invocation.
- The mining step can output an optimal combination, an HTML report, and a snapshot, while the report step can reuse the snapshot to regenerate the report.
- The generated HTML report includes dataset quality checks, univariate rule statistics, combination-rule metrics, all-combination ranking, scatter and precision-recall views, candidate rule pools, and appendix configuration details.
## Use Cases
- Risk-control strategy personnel can replace manual strategy adjustment with a rule-mining flow on prepared sample data.
- Data analysis personnel can inspect feature quality and candidate rules before selecting rule combinations for a target variable.
- Report consumers can open the self-contained HTML file directly in a browser without external resources.
## Technical Details
- The MIT-licensed implementation is pure JavaScript ESM with zero build steps and zero external dependencies.
- The package includes an entry file for registering tools and skills, an engine file for CSV parsing, quality checks, single-rule evaluation, and combination search, and a report file for self-contained HTML generation with inline CSS and SVG.
- Installation can use the npm package dsh-plugin-risk-rule-design through dsh plugin --profile web install, which automatically registers the bundle into the profile.
- GitHub installation adds the dependency but requires manually appending the package name to the profile bundle list and restarting dsh web.
## Notes
- The README states that the plugin is still being improved and may have issues during use.
- Users must provide a dataset path, specify the target field, and identify fields to exclude when invoking the skill.
- The GitHub installation path does not automatically register the bundle, so manual profile configuration is required.
安装Install
dsh plugin --profile web add "github:pypcfx-glitch/risk-rule-design"
把 pypcfx-glitch/risk-rule-design 加入你的 DSH 配置(web profile)即可启用。
READMEREADME
risk_rule_design:DeepSeek Harness 第一个风控规则挖掘插件
⚠️这个插件是东哥的第一个dsh插件,还在完善中;如使用中有不妥之处,欢迎各位留言指正。
一、插件介绍
一个面向 DeepSeek Harness 的第三方插件:蒸馏《100天风控专家》的思想和方法论,对指定数据集(X/y)进行 数据质检 → 单规则挖掘 → 并行规则集最优组合 → HTML分析报告 的完整流程,解决风控策略人员手动调策略的过程,提高工作效率。
插件注册 3 个工具 + 1 个专家技能:
| 能力 | 名称 | 说明 |
|---|---|---|
| 工具 | rrd_profiling |
第 1 步:X/y 确认与数据质量检查(自动剔除 ID/serialno/常量/近似唯一/高缺失列) |
| 工具 | rrd_mining |
第 2 步:单规则评估 + 并行规则集最优组合(遍历规则先后顺序)+ 默认生成 HTML 报告 |
| 工具 | rrd_report |
第 3 步:基于挖掘快照重新生成/调整 HTML 报告 |
| 技能 | risk-rule-design |
专家方法论(角色、流程、评判标准、报告结构),可被模型/用户加载 |
二、目录结构
risk_rule_design/
├── cordis.yml # 插件补丁覆盖层(绝对路径版,源码直挂用 --patch 或合并进 profile)
├── cordis.patch.yml # 插件补丁(npm 包形态,发布后由 dsh plugin 安装)
├── package.json # npm 发布清单(零依赖)
├── LICENSE # MIT
├── src/
│ ├── index.js # 插件入口:注册工具与技能(零外部依赖)
│ ├── engine.js # 挖掘引擎:CSV 解析、质检、单规则、组合规则搜索(纯逻辑)
│ └── report.js # 自包含 HTML 报告生成(内联 CSS/SVG,无外部资源)
├── demo/
│ ├── make_demo_data.mjs # 演示数据集生成器(含已知潜在规则结构)
│ └── report/smoke_report.html # 演示输出样例(生成物,不入库)
└── test/
├── smoke.mjs # 引擎 + 报告冒烟测试
├── load_plugin.mjs # 插件模块加载测试(桩 ctx)
└── run_tools.mjs # 3 个工具端到端执行 + schema 一致性校验
三、安装
插件是纯 JavaScript(ESM),零构建、零外部依赖。
方式一:从npm安装(推荐)
dsh plugin --profile web install dsh-plugin-risk-rule-design
安装后重启 dsh web 生效;卸载:
dsh plugin --profile web remove dsh-plugin-risk-rule-design
✅ npm 包自带
dsh.bundle.patch,安装命令会自动把包注册进 profile 的dsh.profile.bundles,重启后工具与技能即可用,无需手动配置。
方式二:从Github安装(备选)
dsh plugin --profile web add "github:pypcfx-glitch/risk-rule-design"
⚠️ GitHub 直装只把包加入依赖,不会自动注册 bundle,需手动把包名追加到 profile 的
C:\Users\yaodyu\.dsh\profiles\web\package.json中:
"dsh": {
"profile": {
"bundles": [
"@deepseek-ai/dsh-base",
"@deepseek-ai/dsh-web-app",
"risk-rule-design"
]
}
}
然后重启 dsh web 生效。
提示:两种方式任选其一即可,无需重复安装;推荐方式一(npm 安装一键生效)。
四、使用流程
如何使用这个插件?
为了解决风控策略/数据分析人员的双手,你只需要准备分析样本即可(样本中需包括特征X和目标变量y)。
下面提供一个简单的对话命令模版。
敲入/调用插件risk-rule-design(安装成功后敲入risk应该会自动显示出来),然后将分析样本的绝对文件路径copy过来,并说明y的字段名。
最后执行就可以了。
/risk-rule-design
D:\...\model_data_v1.0.xlsx
分析这个数据集,剔除y_label_30和y_label_7,其中y_label_15是y,X请自行判断。
插件risk-rule-design会按照规则挖掘的分析流程自动执行,并生成报告,执行流转步骤如下:
rrd_profiling(dataset, target) ↓ 确认 X 清单 rrd_mining(dataset, target, features, [objective, hitRateBudget, minBadCoverage, ...]) ↓ 输出最优组合 + HTML 报告 + 快照 rrd_report(snapshot, [title, note]) # 可选
五、HTML报告结构及展示
- 数据集与质量检查:样本/字段/坏率概览、字段清单与剔除决策、质量检查问题、y 分布;
- 单变量效果分析:每个特征的候选规则(命中率、命中坏率、Lift、IV)与可视化条形图;
组合规则效果分析:
- 最优组合总览卡片(精准率、召回率、F1、命中率、Lift、拒绝样本数);
- 最优组合内所有规则 + 累积命中率 / Lift / 召回率 / 边际增益明细;
- 全部组合评估表(按 F1 降序):排名、组合规则、精准率、召回率、F1、命中率、Lift, 最优高亮(top_lift 目标时 ⭐ 标注 top5%);
- 命中率 × Lift 点位图:全部组合散点,最优高亮(可见累加规则后沿「命中率↑、Lift↓」移动);
- 精准率-召回率曲线:全部组合曲线,标注 F1 最高点(即最优组合对应的点),而非拐点;
- 候选规则池与入选情况;
附录:分析配置与约束说明。
报告为自包含 HTML(内联 CSS/SVG,无外部资源),可直接用浏览器打开。
amruthpillai/reactive-resume
anywhere-labs/deepseek-harness-desktop
tt-a1i/archify
strukto-ai/mirage
liustack/modlens
omdsh-dev/DSH-better-sidebar
dsh-market/dsh-market