Py之scorecardpy:scorecardpy的简介、安装、使用方法之详细攻略


car
car 2022-09-19 10:23:34 50970
分类专栏: 资讯

Py之scorecardpy:scorecardpy的简介、安装、使用方法之详细攻略

目录

scorecardpy的简介

scorecardpy的安装

scorecardpy的使用方法

1、基础案例


scorecardpy的简介

       Scorecardpy,由谢士晨博士开发,这个包是 R 包评分卡的 python 版本。 其目标是通过为一些常见任务提供功能,使传统信用风险评分卡模型的开发更容易、更高效

  • 数据切分(split_df)
  • 变量选择(iv,var_filter)
  • 证据权重 (woe) 分箱(woebin、woebin_plot、woebin_adj、woebin_ply)
  • 评分卡缩放 (scorecard, scorecard_ply)
  • 性能评估(perf_eva、perf_psi)

Githubhttps://github.com/shichenxie/scorecardpy
案例
scorecardpy库的使用简介 - 知乎

评分卡建模工具scorecardpy全解读 - 知乎

scorecardpy的安装

pip install scorecardpy

scorecardpy的使用方法

1、基础案例

  1. Traditional Credit Scoring Using Logistic Regression
  2. import scorecardpy as sc
  3. data prepare ------
  4. load germancredit data
  5. dat = sc.germancredit()
  6. filter variable via missing rate, iv, identical value rate
  7. dt_s = sc.var_filter(dat, y="creditability")
  8. breaking dt into train and test
  9. train, test = sc.split_df(dt_s, 'creditability').values()
  10. woe binning ------
  11. bins = sc.woebin(dt_s, y="creditability")
  12. sc.woebin_plot(bins)
  13. binning adjustment
  14. adjust breaks interactively
  15. breaks_adj = sc.woebin_adj(dt_s, "creditability", bins)
  16. or specify breaks manually
  17. breaks_adj = {
  18. 'age.in.years': [26, 35, 40],
  19. 'other.debtors.or.guarantors': ["none", "co-applicant%,%guarantor"]
  20. }
  21. bins_adj = sc.woebin(dt_s, y="creditability", breaks_list=breaks_adj)
  22. converting train and test into woe values
  23. train_woe = sc.woebin_ply(train, bins_adj)
  24. test_woe = sc.woebin_ply(test, bins_adj)
  25. y_train = train_woe.loc[:,'creditability']
  26. X_train = train_woe.loc[:,train_woe.columns != 'creditability']
  27. y_test = test_woe.loc[:,'creditability']
  28. X_test = test_woe.loc[:,train_woe.columns != 'creditability']
  29. logistic regression ------
  30. from sklearn.linear_model import LogisticRegression
  31. lr = LogisticRegression(penalty='l1', C=0.9, solver='saga', n_jobs=-1)
  32. lr.fit(X_train, y_train)
  33. lr.coef_
  34. lr.intercept_
  35. predicted proability
  36. train_pred = lr.predict_proba(X_train)[:,1]
  37. test_pred = lr.predict_proba(X_test)[:,1]
  38. performance ks & roc ------
  39. train_perf = sc.perf_eva(y_train, train_pred, title = "train")
  40. test_perf = sc.perf_eva(y_test, test_pred, title = "test")
  41. score ------
  42. card = sc.scorecard(bins_adj, lr, X_train.columns)
  43. credit score
  44. train_score = sc.scorecard_ply(train, card, print_step=0)
  45. test_score = sc.scorecard_ply(test, card, print_step=0)
  46. psi
  47. sc.perf_psi(
  48. score = {'train':train_score, 'test':test_score},
  49. label = {'train':y_train, 'test':y_test}
  50. )

文章知识点与官方知识档案匹配,可进一步学习相关知识
Python入门技能树预备知识Python简介123796 人正在系统学习中

网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。

本文链接:https://www.xckfsq.com/news/show.html?id=1752
赞同 0
评论 0 条
carL0
粉丝 0 发表 10 + 关注 私信
上周热门
如何使用 StarRocks 管理和优化数据湖中的数据?  2691
【软件正版化】软件正版化工作要点  2655
统信UOS试玩黑神话:悟空  2559
信刻光盘安全隔离与信息交换系统  2247
镜舟科技与中启乘数科技达成战略合作,共筑数据服务新生态  1117
grub引导程序无法找到指定设备和分区  769
江波龙2025届校园招聘宣讲会行程大放送  28
点击报名 | 京东2025校招进校行程预告  25
海康威视2025校招|海康机器人,邀你共创工业智能化未来!  24
金山办公2024算法挑战赛 | 报名截止日期更新  22
本周热议
我的信创开放社区兼职赚钱历程 40
今天你签到了吗? 27
信创开放社区邀请他人注册的具体步骤如下 15
如何玩转信创开放社区—从小白进阶到专家 15
方德桌面操作系统 14
我有15积分有什么用? 13
用抖音玩法闯信创开放社区——用平台宣传企业产品服务 13
如何让你先人一步获得悬赏问题信息?(创作者必看) 12
2024中国信创产业发展大会暨中国信息科技创新与应用博览会 9
中央国家机关政府采购中心:应当将CPU、操作系统符合安全可靠测评要求纳入采购需求 8

加入交流群

请使用微信扫一扫!