Py之scorecardpy:scorecardpy的简介、安装、使用方法之详细攻略
2023-09-14 09:04:44 时间
Py之scorecardpy:scorecardpy的简介、安装、使用方法之详细攻略
目录
scorecardpy的简介
Scorecardpy,由谢士晨博士开发,这个包是 R 包评分卡的 python 版本。 其目标是通过为一些常见任务提供功能,使传统信用风险评分卡模型的开发更容易、更高效。
- 数据切分(split_df)
- 变量选择(iv,var_filter)
- 证据权重 (woe) 分箱(woebin、woebin_plot、woebin_adj、woebin_ply)
- 评分卡缩放 (scorecard, scorecard_ply)
- 性能评估(perf_eva、perf_psi)
Github:https://github.com/shichenxie/scorecardpy
案例
scorecardpy库的使用简介 - 知乎
scorecardpy的安装
pip install scorecardpy
scorecardpy的使用方法
1、基础案例
# Traditional Credit Scoring Using Logistic Regression
import scorecardpy as sc
# data prepare ------
# load germancredit data
dat = sc.germancredit()
# filter variable via missing rate, iv, identical value rate
dt_s = sc.var_filter(dat, y="creditability")
# breaking dt into train and test
train, test = sc.split_df(dt_s, 'creditability').values()
# woe binning ------
bins = sc.woebin(dt_s, y="creditability")
# sc.woebin_plot(bins)
# binning adjustment
# # adjust breaks interactively
# breaks_adj = sc.woebin_adj(dt_s, "creditability", bins)
# # or specify breaks manually
breaks_adj = {
'age.in.years': [26, 35, 40],
'other.debtors.or.guarantors': ["none", "co-applicant%,%guarantor"]
}
bins_adj = sc.woebin(dt_s, y="creditability", breaks_list=breaks_adj)
# converting train and test into woe values
train_woe = sc.woebin_ply(train, bins_adj)
test_woe = sc.woebin_ply(test, bins_adj)
y_train = train_woe.loc[:,'creditability']
X_train = train_woe.loc[:,train_woe.columns != 'creditability']
y_test = test_woe.loc[:,'creditability']
X_test = test_woe.loc[:,train_woe.columns != 'creditability']
# logistic regression ------
from sklearn.linear_model import LogisticRegression
lr = LogisticRegression(penalty='l1', C=0.9, solver='saga', n_jobs=-1)
lr.fit(X_train, y_train)
# lr.coef_
# lr.intercept_
# predicted proability
train_pred = lr.predict_proba(X_train)[:,1]
test_pred = lr.predict_proba(X_test)[:,1]
# performance ks & roc ------
train_perf = sc.perf_eva(y_train, train_pred, title = "train")
test_perf = sc.perf_eva(y_test, test_pred, title = "test")
# score ------
card = sc.scorecard(bins_adj, lr, X_train.columns)
# credit score
train_score = sc.scorecard_ply(train, card, print_step=0)
test_score = sc.scorecard_ply(test, card, print_step=0)
# psi
sc.perf_psi(
score = {'train':train_score, 'test':test_score},
label = {'train':y_train, 'test':y_test}
)
相关文章
- pycharm安装激活码_超影能激活福袋吗
- pycharm中pyqt5使用方法_pycharm安装pyqt5失败
- Pycharm中安装Pygame方法「建议收藏」
- idea安装与配置【包含了idea中每一个英文字母的翻译和使用方法】
- 04-基于CentOS7安装RabbitMQ3.10.7
- LabVIEW 2020安装教程和汉化方法(附安装包)
- 手把手教你如何在腾讯云上安装hadoop3.x伪集群的方法
- Linux下redis5.0.5的安装过程与配置方法
- Linux下安装pyenv的方法
- Win10安装Linux系统的教程图解
- 快速安装Linux下的PyPy(linux安装pypy)
- 深入MySQL:全面掌握插件的安装方法(mysql插件安装)
- 在 VirtualBox 上安装 Kali Linux:最快速和最安全的方法
- Linux安装教程:掌握正确的序列号码输入方法(linux安装号码)
- 拒绝若依,无需安装Redis(若依不使用redis)
- MySQL安装时只能选择C盘解决方法(mysql不能装在其他盘)
- SQLServer2005更改安装路径目录的方法小结
- PHP图片库imagemagick安装方法