# NOT RUN {
library(data.table)
library(scorecard)
# Traditional Credit Scoring Using Logistic Regression
# load germancredit data
data("germancredit")
# rename creditability as y
dt = data.table(germancredit)[, `:=`(
y = ifelse(creditability == "bad", 1, 0),
creditability = NULL
)]
# woe binning ------
bins = woebin(dt, "y")
dt_woe = woebin_ply(dt, bins)
# glm ------
m1 = glm( y ~ ., family = "binomial", data = dt_woe)
# summary(m1)
# Select a formula-based model by AIC
m_step = step(m1, direction="both", trace=FALSE)
m2 = eval(m_step$call)
# summary(m2)
# predicted proability
dt_pred = predict(m2, type='response', dt_woe)
# performance ------
# Example I # only ks & auc values
perf_eva(dt_woe$y, dt_pred, show_plot=FALSE)
# Example II # ks & roc plot
perf_eva(dt_woe$y, dt_pred)
# Example III # ks, lift, roc & pr plot
perf_eva(dt_woe$y, dt_pred, type = c("ks","lift","roc","pr"))
# }
Run the code above in your browser using DataLab