Yihuier
一会儿轻松解决信用评分卡建模
基于 Scorecard--Function 重构的面向对象版本。
特性
- 面向对象设计 - 统一的 Yihuier 类管理数据和状态
- 完整建模流程 - EDA → 数据处理 → 分箱 → 变量选择 → 模型评估 → 评分卡实现 → 监控
- 特征工程 - 交叉特征、数学变换、缺失指示符、批量交叉(带 IV 预筛)
- 模块化架构 - 9个独立模块,职责清晰
- 类型提示 - 完整的类型注解,更好的IDE支持
- 可选 optbinning 分箱 -
pip install yihuier[optimal]后可用method='optbinning',强制 WOE 单调、求解器更优(真实数据上 IV 均值 +10%、单调变量 50/93 vs 自研 1/93),原生方法不受影响
快速开始
安装
# 使用 pip
pip install yihuier
# 或使用 uv
uv pip install yihuier
可选依赖
| 安装命令 | 额外能力 |
|---|---|
pip install yihuier[optimal] |
启用 method='optbinning'——委托 optbinning 求最优切点(强制 WOE 单调、求解器更优),内置兼容垫片,无需降级 sklearn |
pip install yihuier[profiling] |
EDA 自动报告(ydata-profiling) |
pip install yihuier[dev] |
开发/测试工具(pytest、ruff) |
pip install yihuier[all] |
以上全部 |
不安装
[optimal]也能正常使用所有原生分箱方法(ChiMerge / 等频 / 等距 / 自定义)。
基础使用
import pandas as pd
from yihuier import Yihuier
# 加载数据
data = pd.read_csv('data.csv')
yh = Yihuier(data, target='dlq_flag')
# 数据预处理
data_clean = yh.dp_module.delete_missing_var(threshold=0.15)
# 变量分箱
bin_df, iv_value = yh.binning_module.binning_num(
col_list=['v1', 'v2', 'v3'],
max_bin=5,
method='ChiMerge'
)
# WOE转换
woe_df = yh.binning_module.woe_df_concat()
data_woe = yh.binning_module.woe_transform()
# 变量选择
xg_imp, xg_rank, xg_cols = yh.var_select_module.select_xgboost(
col_list=data_woe.drop(['dlq_flag'], axis=1).columns.tolist(),
imp_num=10
)
# 模型训练
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(data_woe[xg_cols], data_woe['dlq_flag'])
# 模型评估
y_pred = model.predict_proba(x_test)[:, 1]
yh.me_module.plot_roc(y_test, y_pred)
yh.me_module.plot_model_ks(y_test, y_pred)
模块概览
| 模块 | 功能 | 文档 |
|---|---|---|
EDAModule |
探索性数据分析 | 📖 EDA 模块 |
DataProcessingModule |
数据预处理 | 📖 数据预处理 |
FeatureEngineeringModule |
特征工程 | 📖 特征工程模块 |
BinningModule |
变量分箱 | 📖 分箱模块 |
VarSelectModule |
变量选择 | 📖 变量选择 |
ModelEvaluationModule |
模型评估 | 📖 模型评估 |
ScorecardImplementModule |
评分卡实现 | 📖 评分卡实现 |
ScorecardMonitorModule |
评分卡监控 | 📖 评分卡监控 |
ClusterModule |
聚类分析 | 📖 聚类模块 |
PipelineModule |
流水线 | 📖 流水线模块 |
📚 完整文档
开发
# 克隆项目
git clone https://github.com/ency/yihuier.git
cd yihuier
# 安装开发依赖
uv pip install -e ".[dev]"
# 运行测试
pytest tests/ -v
# 代码格式化
ruff format yihuier/
ruff check yihuier/
许可证
MIT License
致谢
- 原项目: Scorecard--Function
- 相关文章: 知乎专栏
Metadata
Release files for yihuier 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| yihuier-0.4.0.tar.gz | 1.6 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| yihuier-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.7 MB
Release files / yihuier-0.4.0.tar.gz
| Download URL | yihuier-0.4.0.tar.gz |
|---|---|
| Size | 1.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a1789ab9b11bc100c6eb2a15f52fa9112bc0cc588e228b5eb886f6946dc3d8ef
|
|
BLAKE2b-256 checksum How to use checksums |
5e0f9f14b76e39745b82ce59bd560a65a5ad46220c1612dd20edc8e4d3472532
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.
Transparency logRelease files / yihuier-0.4.0-py3-none-any.whl
| Download URL | yihuier-0.4.0-py3-none-any.whl |
|---|---|
| Size | 50.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cb7f2a2ea4eea2951a9939090920ee8598d9c6d7522794b0eb7631ee75664f24
|
|
BLAKE2b-256 checksum How to use checksums |
34f5f4ef2fda7c42b440dd61fe52536d3d335af8cded9fa9d7254bc618cff402
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.
Transparency log