Skip to main content

risk-rule-design

11Stars0Forks0Issues0Watchers

Financial risk control rule mining plugin for DSH: automatically performs data quality inspection, single rule mining, parallel OR rule combination optimization search, and outputs self-contained HTML reports.

Evidence5/5methodologySourceInstallMaintenanceDSH versionSecurity scan
Machine-auditedInstall commandRepo verifieddsh-plugin topicLicenseREADMEAI wiki
Language
JavaScript
License
MIT
Branch
main
agent-skilldeepseek-harnessdsh-pluginfinance-risk-analysisrisk-analysis

Install

cmdweb profile
$ dsh plugin --profile web add dsh-plugin-risk-rule-design

Run the command above in your terminal to install this plugin via the dsh CLI. You can switch Profile in the top-right corner. New to dsh? Read the beginner tutorial

Install via your agent

Install the DeepSeek Harness plugin pypcfx-glitch/risk-rule-design for me: review the repository at https://github.com/pypcfx-glitch/risk-rule-design first, then run the install command and verify the plugin loads successfully.

Paste this instruction to the DSH Web GUI assistant — it will install and verify for you.

One-Line Description

Provides financial risk control rule mining capability for DSH: Given a CSV dataset with binary classification labels (features X and good/bad label y), automatically completes data quality inspection, single-rule mining, parallel OR rule combination optimal search, and outputs a self-contained HTML analysis report.

Core Capabilities

  • Automatic Data Quality Inspection: Identifies and removes useless features such as ID/serial numbers/constants/near-unique/high-missing values, calculates y distribution and duplicate rows, provides recommended X list
  • Single-Rule Mining: For continuous variables, traverses thresholds by quantiles (default 1/3/5/95/97/99%) and attempts two directions "select larger x>=q / select smaller x<=q" to generate candidates; for categorical variables, takes high bad-concentration single values and unions; missing values are also used as a candidate rule type
  • Parallel OR Rule Combination Optimal Search: Uses layer-by-layer tree traversal strategy, first uses top 5% single-rule Lift as first rule seeds in rotation, then expands layer by layer by gain until recall cannot be improved further
  • Five Evaluation Objectives: Default f1 (most balanced precision × recall), also supports top_lift / composite / max_lift / min_hit
  • Self-Contained HTML Analysis Report: Inline CSS and SVG charts, including dataset overview, univariate bar charts, combination accumulation curves, hit rate-Lift scatter plots, precision-recall curves, can be opened directly in browser
  • **Simultaneously registers 1 expert skill "risk-rule-design" and 3 tools (rrd_profiling / rrd_mining / rrd_report), which can be invoked by models or users in DSH sessions

Technical Implementation

  • Language: JavaScript (ESM, type: module)
  • Key Dependencies: None (only uses Node built-in node:fs/promises, node:path and relative imports)
  • Architecture Pattern: Inserts plugin into DSH host via cordis.patch.yml (npm package form), calls tools.register and skills.register in apply(ctx) to register tools and skills; combination search uses compact bitsets (Bits/Uint32Array + popcount table) to accelerate hit calculation
  • Entry File: src/index.js (registration entry); Core engine src/engine.js (CSV parsing, type inference, single-rule mining, combination search); Report generation src/report.js (self-contained HTML)

Use Cases

Used by risk control strategy personnel and data analysts when they need to perform rejection rule mining on historical samples with good/bad labels. Typical usage: you only need to provide the CSV dataset path to the plugin and tell it which column is y (e.g., default_flag), and the plugin will automatically run the entire flow of "data inspection → single rules → combination → report" and tell you what the best combination looks like "reject if any rule is triggered".

Prerequisites & Compatibility

DependencyMinimum VersionDescription
DSH HostNot declaredInjected via cordis.patch.yml, requires DSH to support cordis patch mechanism
Node>= 18From package.json#engines.node; plugin has zero dependencies, only uses Node built-in modules
PlatformCross-platformPure JavaScript, no native modules, no os/cpu restrictions
Native ModulesNoneZero external dependencies, no node-gyp / native extensions

Installation

dsh plugin --profile web add dsh-plugin-risk-rule-design

Configuration Options

This plugin does not require a configuration file itself. The core parameters for the three tools (adjustable options for rrd_mining) are as follows:

ParameterTypeDescriptionDefault
datasetString (required)Absolute path to the dataset CSV file (must include header row)—
targetString (required)Column name of target variable y (binary: bad=1 / good=0)—
objectiveEnumCombination evaluation objective: f1 / top_lift / composite / max_lift / min_hitf1
hitRateBudget0~1Upper limit of combination hit rate (pass rate reduction) budget0.5
cutQuantilesInteger arrayQuantiles (%) for continuous variable splitting, traverses "select larger/select smaller" two directions[1, 3, 5, 95, 97, 99]
minSupport0~1Minimum support (hit ratio) for single rules0.01
minLift1~100Minimum Lift for single rules1.05
maxRules1~12Maximum number of combination rules8
maxCandidates1~40Maximum size of candidate rule pool14
reportDirStringOutput directory for HTML report and mining snapshotsDataset directory
titleStringReport titleRisk Control Rule Mining Analysis Report

rrd_profiling and rrd_report have fewer parameters: profiling only requires dataset+target (plus optional features/exclude); report requires snapshot (required) + optional reportDir/title/note.

FAQ

Q: What format does the target variable y need to be in?

A: Must be binary classification labels. The engine accepts equivalent notations such as 0/1, true/false, good/bad, 正常/违约, 违约/未逾期, 是/否, yes/no, etc., and automatically maps them to bad=1/good=0. Single value (all 0 or all 1) will directly throw an error "Target column has single value, cannot mine".

Q: What format must the dataset be in?

A: Only CSV (with header row) is supported. The engine has a built-in CSV parser, supporting quoted values, escaped quotes, commas/newlines within quotes, CRLF, BOM, etc. Note that .xlsx appearing in README examples is for guidance, the engine actually only reads CSV text; xlsx needs to be converted to CSV first.

Q: Will it run slowly when the data volume is large?

A: In the combination search phase, if rows exceed 50000, it will automatically sample with equal step size for acceleration, but all final metrics (F1, recall, hit rate, Lift, etc.) will be precisely recalculated on the full dataset, and the report will note whether sampling was used. Duplicate row check is skipped when data exceeds 200k to save memory.

Q: Does the output HTML report need internet connection?

A: No. The report is self-contained HTML with CSS and all charts (scatter plots, PR curves, bar charts) inline in the file, with no external resource references; it can be opened directly in any browser.

Q: What's the difference between the five evaluation objectives (objective)?

A: f1 (default) = most balanced precision and recall with both large (max F1); top_lift = smallest hit rate within top 5% combination Lift; composite = max lift×(1−hit_rate); max_lift = maximize lift within hit rate budget; min_hit = minimize hit rate when Lift meets threshold. Among these, f1/top_lift are not constrained by minBadCoverage.

Q: How to uninstall?

A: Run dsh plugin --profile web remove dsh-plugin-risk-rule-design, then restart dsh web.

Q: Too many ID/serial number fields are automatically removed, can they be kept?

A: The engine automatically removes ID/serial number columns using three rules: column name regex (e.g., _id, serialno, 编号, 手机号) + cardinality check (≈ sample size considered near-unique) + constant detection. If you really need to keep them, you can explicitly specify the columns to keep using features when calling rrd_profiling.

Learning Curve

Beginner — Prepare a CSV (with binary labels) + run rrd_mining once to get the optimal combination and HTML report; only when you want fine-tuning parameters (objective, cutQuantiles, branchMin, etc.) do you need to further understand the layer-by-layer tree traversal search logic.

Known Issues & Limitations

  • Only accepts CSV text, does not directly read xlsx/excel; paths with .xlsx in README examples will trigger "Dataset file not found" error
  • Target column must be binary: single value (all 0 or all 1), non-binary (multiple values like 0/1/2) will both throw errors and prompt legal value range
  • When data volume > 200000 rows, duplicate row check is skipped (only hinted at info level in README/tool description, does not block process)
  • Categorical variable union rules only greedily select top 12 high bad-concentration values (engine.js:390), may not cover long-tail for categorical columns with many values
  • README self-states "still improving, welcome comments and corrections" at the beginning, still in early iteration stage
  • Duplicate row check maintains a Set in memory (containing concatenated strings of all columns), memory usage is notable when sample size reaches hundreds of thousands

Read the usage guide →

Install steps, key points, FAQ and compatibility for this plugin — auto-derived from indexed fields.

Listing badge

Listed on deepseek-plugin.org
[![Listed on deepseek-plugin.org](https://img.shields.io/badge/listed_on-deepseek--plugin.org-007EC6)](https://deepseek-plugin.org/plugins/pypcfx-glitch/risk-rule-design)

Paste this markdown into your GitHub README to link back to this listing. The badge only states the listing — not a security endorsement.

← Back to plugin directory