日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

R语言 scorecard包 评分卡

發(fā)布時(shí)間:2025/3/21 编程问答 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 R语言 scorecard包 评分卡 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我會(huì)把文章及時(shí)的更新到公共號(hào)上,歡迎大家的關(guān)注。

?

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))

# 數(shù)據(jù)集劃分為訓(xùn)練集和測(cè)試集
dt_list <- split_df(dt_s)
train <- dt_list$train
test <- dt_list$test

# woe 分箱 自動(dòng)分箱
bins <- woebin(dt_s, y="creditability")

# 繪制分箱后的壞賬率可視化,對(duì)應(yīng)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)

# 模型性能驗(yàn)證 ks和roc
# 預(yù)測(cè)的概率
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')

# 生成評(píng)分卡
card <- scorecard(bins, m2)
card

train_score <- scorecard_ply(train, card, print_step = 0)
# 驗(yàn)證集評(píng)分
test_score <- scorecard_ply(test, card, print_step = 0)

print(train_score)


print(test_score)

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

?

總結(jié)

以上是生活随笔為你收集整理的R语言 scorecard包 评分卡的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。