Learn R Programming

scorecard (version 0.1.2)

perf_plot: KS, ROC, Lift, PR

Description

perf_plot provides performance evaluations, such as kolmogorov-smirnow(ks), ROC, lift and precision-recall curves, based on provided label and predicted probability values.

Usage

perf_plot(label, pred, title = "train", groupnum = 20, type = c("ks",
  "roc"), show_plot = TRUE, seed = 186)

Arguments

label

Label values, such as 0s and 1s, 0 represent for good and 1 for bad.

pred

Predicted probability values.

title

Title of plot, default "train".

groupnum

The group numbers when calculating bad probability, default 20.

type

Types of performance plot, such as "ks", "lift", "roc", "pr". Default c("ks", "roc").

show_plot

Logical value, default TRUE. It means whether to show plot.

seed

An integer. The specify seed is used for random sorting data, default: 186.

Value

ks, roc, lift, pr

See Also

perf_psi

Examples

Run this code
# 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")
m2 <- eval(m_step$call)
# summary(m2)

# predicted proability
dt_woe$pred <- predict(m2, type='response', dt_woe)

# performance ------
# Example I # only ks & auc values
perf_plot(dt_woe$y, dt_woe$pred, show_plot=FALSE)

# Example II # ks & roc plot
perf_plot(dt_woe$y, dt_woe$pred)

# Example III # ks, lift, roc & pr plot
perf_plot(dt_woe$y, dt_woe$pred, type = c("ks","lift","roc","pr"))
# }

Run the code above in your browser using DataLab