• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

R语言 scorecard包 评分卡

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

library(scorecard)
data("germancredit")
print(dim(germancredit))
print(names(germancredit))
print(head(germancredit[,20:21]))


# 变量选择
dt_s <- var_filter(germancredit, y="creditability")
print(dim(dt_s))

# 数据集划分为训练集和测试集
dt_list <- split_df(dt_s)
train <- dt_list$train
test <- dt_list$test

# woe 分箱 自动分箱
bins <- woebin(dt_s, y="creditability")

# 绘制分箱后的坏账率可视化,对应14张图,这里只展示最后一张
woebin_plot(bins)

train_woe <-  woebin_ply(train, bins)
test_woe <-  woebin_ply(test, bins)
print(dim(train_woe))
print(dim(test_woe))


m1 <- glm( creditability ~ ., family = binomial(), data = train_woe)
summary(m1)

# 逐步回归选择变量
m_step <- step(m1, direction="both", trace = FALSE)
m2 <- eval(m_step$call)
summary(m2)

# 模型性能验证 ks和roc
# 预测的概率
train_pred <- predict(m2, train_woe, type = 'response')
test_pred <- predict(m2, test_woe, type = 'response')

# 性能
train_perf <- perf_eva(train$creditability, train_pred, title = 'train')


test_perf <- perf_eva(test$creditability, test_pred, title = 'test')

# 生成评分卡
card <- scorecard(bins, m2)
card

train_score <- scorecard_ply(train, card, print_step = 0)
# 验证集评分
test_score <- scorecard_ply(test, card, print_step = 0)

print(train_score)


print(test_score)

# 模型的稳定性度量
# psi
psi_result <- perf_psi(
  score = list(train = train_score, test = test_score),
  label = list(train = train$creditability, test = test$creditability)
)


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
R语言学习——条件筛选发布时间:2022-07-18
下一篇:
R语言实战(第2版)发布时间:2022-07-18
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap