Skip to content

charlieviettq/awesome-agent-skill / .claude/skills/algo-risk-credit

"algo-risk-credit"

Verified

"Build credit scoring models to predict default probability from borrower characteristics. Use this skill when the user needs to assess creditworthiness, build a credit scorecard, or evaluate lending risk — even if they say 'predict default risk', 'credit scoring', or 'loan approval model'.".

FileKindSize
SKILL.mdskill md4.2 KB
examples/sample_scenario.mdmarkdown5.4 KB
references/reject-inference.mdmarkdown10.5 KB
references/woe-binning.mdmarkdown11.1 KB

examples/sample_scenario.md

View on GitHub
# Example: 台灣中小企業放款信用評分模型

## Scenario

**公司**: 富邦 FinTech 旗下小額貸款平台「快貸通」  
**日期**: 2024-Q4  
**請求者**: 風控分析師 Vivian Chen

快貸通提供無擔保個人信貸,月申請量約 8,000 件。現行評分模型是 2021 年建置的邏輯迴歸,最近 PSI 監控警報顯示模型可能偏移。Vivian 需要重建信用評分模型,並確認新模型在通過審核後能正式上線。

**可用資料**:
- 訓練集:2022-01 ~ 2023-12,共 45,000 筆申請(已核准)
- 驗證集:2024-01 ~ 2024-06,共 12,000 筆
- 觀察期:核准後 12 個月內有 90 天逾期 = 壞帳(Default=1)
- 壞帳率:訓練集 3.8%,驗證集 4.7%(↑ 顯示族群漂移)

---

## Analysis

### Phase 1: 輸入驗證

**特徵清單(核准當下可取得)**:

| 特徵 | 說明 | 缺失率 |
|------|------|--------|
| `monthly_income` | 月收入(NT$) | 2.1% |
| `dti` | 負債收入比(%) | 0.8% |
| `credit_history_months` | 信用歷史長度(月) | 0% |
| `delinquency_count_24m` | 過去 24 月逾期次數 | 0% |
| `utilization_rate` | 信用卡使用率(%) | 5.3% |
| `inquiry_count_6m` | 過去 6 月查詢次數 | 0% |
| `loan_amount_requested` | 申請金額(NT$) | 0% |

**Gate 檢查**:
- 壞帳事件數:45,000 × 3.8% = **1,710 件** ✓(>300 門檻)
- 特徵皆在申請當下可取得 ✓
- 缺失以訓練集中位數填補(`utilization_rate` 缺失最多,用 45% 填補)

> ⚠️ 注意:訓練集為核准樣本(OTB),存在**拒絕推斷偏誤**,須處理。

---

### Phase 2: 核心演算法

#### 2a. WOE 分箱(邏輯迴歸路徑)

以 `utilization_rate` 為例:

| 區間 | 樣本數 | 壞帳率 | WOE | IV 貢獻 |
|------|--------|--------|-----|---------|
| 0–30% | 18,200 | 1.9% | +0.62 | 0.041 |
| 30–60% | 14,500 | 3.5% | +0.08 | 0.001 |
| 60–80% | 8,100 | 5.8% | -0.38 | 0.018 |
| 80–100% | 4,200 | 9.2% | -0.94 | 0.052 |

IV 合計 = **0.112**(有預測力,保留)

所有特徵 IV 彙總:

| 特徵 | IV |
|------|-----|
| `delinquency_count_24m` | 0.31 |
| `utilization_rate` | 0.11 |
| `dti` | 0.09 |
| `inquiry_count_6m` | 0.08 |
| `credit_history_months` | 0.07 |
| `monthly_income` | 0.04 |
| `loan_amount_requested` | 0.02 |

> `loan_amount_requested` IV < 0.02,考慮排除,但保留以利監管說明。

#### 2b. 模型訓練

使用 **L2 正則化邏輯迴歸**(監管偏好、可解釋):

```
logit(PD) = -3.82
           + 1.45 × WOE(delinquency_count_24m)
           + 0.89 × WOE(utilization_rate)
           + 0.67 × WOE(dti)
           + 0.54 × WOE(inquiry_count_6m)
           + 0.48 × WOE(credit_history_months)
           + 0.21 × WOE(monthly_income)
           + 0.09 × WOE(loan_amount_requested)
```

#### 2c. 校準(Calibration)

Platt Scaling 在驗證集校準結果:

| 分數十分位 | 預測 PD | 實際違約率 | 誤差 |
|-----------|---------|-----------|------|
| D1(最低風險) | 0.8% | 0.9% | +0.1% |
| D3 | 2.1% | 2.3% | +0.2% |
| D5 | 3.9% | 4.1% | +0.2% |
| D7 | 6.8% | 7.2% | +0.4% |
| D10(最高風險) | 18.4% | 19.1% | +0.7% |

校準誤差 < 1pp,**通過**。

#### 2d. 分數轉換

```
Score = 600 + 40 × log(odds)
       其中 log(odds) = log((1-PD)/PD)
       設計基準點:PD=5% → Score=600, 每 40 分 odds 翻倍
```

分數範圍實際分布:340–820,截斷至 **350–800**。

#### 2e. 拒絕推斷處理

訓練集為已核准樣本,用 **Fuzzy Augmentation** 補正:
- 推估被拒絕樣本(約 15% 拒絕率)的壞帳率 = 核准邊緣樣本(分數 420–480)壞帳率 × 1.8 倍
- 將虛擬壞帳樣本加權 0.3 重新訓練
- AUC 幾乎不變(+0.001),但高分段 PD 校準改善

---

### Phase 3: 驗證

| 指標 | 訓練集 | 驗證集 | 門檻 | 狀態 |
|------|--------|--------|------|------|
| AUC | 0.81 | **0.79** | > 0.70 | ✓ |
| KS 統計量 | 0.48 | **0.44** | > 0.30 | ✓ |
| Gini 係數 | 0.62 | **0.58** | — | 參考 |
| PSI(vs 訓練) | — | **0.09** | < 0.25 | ✓ |
| 校準 RMSE | — | **0.003** | < 0.01 | ✓ |

**公平性測試**(性別、年齡層):
- 對 30 歲以下族群 AUC = 0.76,30 歲以上 = 0.80,差異在可接受範圍
- 未使用郵遞區號、族裔相關代理變數 ✓

---

## Result

### 單筆申請輸出範例

**申請人**: 王大明,月收入 NT$55,000,DTI 38%,信用歷史 62 個月,逾期 0 次,使用率 72%,6 月查詢 2 次

```json
{
  "score": 641,
  "pd": 0.058,
  "risk_grade": "C",
  "top_risk_factors": [
    {"factor": "high_utilization_rate_72pct", "impact": -38},
    {"factor": "dti_38pct", "impact": -22},
    {"factor": "inquiry_count_6m_2", "impact": -11}
  ],
  "metadata": {
    "model": "logistic_regression_woe",
    "auc": 0.79,
    "vintage": "2024-Q4",
    "reject_inference": "fuzzy_augmentation"
  }
}
```

**決策建議**: 分數 641,Grade C → 條件核准(降額至 NT$150,000,利率 12.5%)。分數 < 600 拒絕,> 700 標準核准。

### 模型部署摘要

| 項目 | 舊模型(2021) | 新模型(2024-Q4) |
|------|--------------|----------------|
| AUC | 0.74 | **0.79** |
| PSI 當前 | 0.31(⚠️ 超標) | 0.09 ✓ |
| 校準誤差(D10) | 3.2% | 0.7% |
| 拒絕推斷 | 未處理 | Fuzzy Augmentation |

> **後續監控**: 每月計算 PSI;PSI > 0.15 發出警告,> 0.25 觸發重訓。2025-Q2 進行首次 vintage 回顧。
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall