Skip to main content

bbbrisk-bbb风控包

本代码由bbbdata为评分卡专门开发的小贷风控包,目前提供的功能主要是构建评分卡

bbbrisk的优点是,不仅仅是单纯的提供评分卡模型,而是实际构建评分卡时一切可能用到的功能(例如,变量的分析、分箱,模型的训练,评分卡表的构建,最终的报告等等)

评分卡教程、API说明、源代码详见文末

Install and Upgrade · 安装与升级

pip install bbbrisk    # to install
pip install -U bbbrisk # to upgrade

bbbrisk依赖于numpy、pandas和sklearn包,最好尽可能保障已经安装了这三个包

Key features · 主要功能

bbbrisk包括(不局限)如下功能:

  • 自带小贷数据
  1. 小贷原始变量数据

  2. 小贷分箱变量数据

  • 对变量进行分箱与分
  1. 打印单变量手动分箱的结果

  2. 打印单变量自动分箱结果

    等频、等距、卡方分箱、KS分箱、决策树分箱等

  3. 对所有变量直接自动分箱

  • 数据转换
  1. 将数据转换为分箱数据

  2. 将分箱数据转换为woe数据

  • 构建模型与评分卡
  1. 支持直接用原始数据与分箱设置进行建模

  2. 支持使用分箱后的数据进行建模

  3. 支持设置模型转评分的参数

  4. 支持按分数范围进行模型转评分

  5. 支持模型预测(输出概率)

  6. 支持评分预测(输出评分)

  • 写报告时需要的内容
  1. 计算阈值表

  2. 绘画分数分布图

更多功能参见每个API的说明与示例~

Demo · 使用示例

import bbbrisk as br

#加载数据                                                              
data = br.datasets.load_bloan()                                        # 加载数据
x = data.iloc[:,:-1]                                                   # 变量数据
y = data['is_bad']                                                     # 标签数据

# 构建评分卡
bin_sets  = br.bins.batch.autoBins(x, y,enum_var=['city','marital'])   # 自动分箱,必须指出哪些是枚举变量
model,card = br.model.scoreCard(x,y,bin_sets)                          # 构建评分卡
score      = card.predict(x[card.var])                                 # 用评分卡进行评分

# 计算阈值表与分数分布图
thd_tb    = br.report.get_threshold_tb(score,y,bin_step=10)            # 阈值表
br.report.draw_score_disb(score,y,bin_step=10,figsize=(14, 4))         # 分数分布

# 打印结果
print('\n-----【 模型性能评估 】----')
print('* 模型训练AUC:',model.train_auc)                                # 打印模型训练数据集的AUC
print('* 模型测试AUC:',model.test_auc)                                 # 打印模型测试数据集的AUC
print('* 模型训练KS:',model.train_ks)                                  # 打印模型训练数据集的KS
print('* 模型测试KS:',model.test_ks)                                   # 打印模型测试数据集的KS
													                   
print('\n--------【 模型 】---------')                                 
print('* 模型使用的变量:',model.var)                                   # 模型最终使用的变量
print('* 模型权重:',model.w)                                           # 模型的变量权重
print('* 模型阈值:',model.b)                                           # 模型的阈值
													                   
print('\n--------【 评分卡 】---------')    
print('\n* 特征得分featureScore:   \n' ,card.featureScore      )       # 特征得分
print('\n* 基础得分baseScore:        ' ,card.baseScore         )       # 基础分

在上述代码中,展示了如何使用自动分箱构建一个评分卡,并打模型的AUC、KS,以及构建好的评分卡表,

进一步地,用构建好的评分卡对样本进行评分,并计算出阈值表与分数分布图

Documents · 文档

更新日志

  • v1.0.2: 优化函数名称与函数功能
  • v1.0.1: 添加数据
  • v1.0.0: 初步上传

Metadata

Release files for bbbrisk 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bbbrisk 1.0.2
File Size Uploaded
bbbrisk-1.0.2.tar.gz 671.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bbbrisk 1.0.2
File Interpreter ABI Platform
bbbrisk-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 1.4 MB

Release files / bbbrisk-1.0.2.tar.gz

Download URL bbbrisk-1.0.2.tar.gz
Size 671.7 kB
Tags Source
SHA-256 checksum
How to use checksums
deeef8e6ec3e3073c3f30213aea71f17e11fdf0313e8151ecaafe2826840bb01
BLAKE2b-256 checksum
How to use checksums
220d84db1370c973a994ac0c92371ee1df3263187d4b4a682fa0d2aa469c0bea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Release files / bbbrisk-1.0.2-py3-none-any.whl

Download URL bbbrisk-1.0.2-py3-none-any.whl
Size 710.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
719305ad1807f49059a7ecbf94991d2c53d205a91d258a3856449697ced7a44c
BLAKE2b-256 checksum
How to use checksums
6b65c4a6fa748121cb2dfaab452ab2d093210db5cffb73d2048dab0dc9fb8b7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page