encode.woe {PDtoolkit}R Documentation

Encode WoE

Description

encode.woe implements replacement of character vector values with WoE values for a given mapping scheme. This procedure is one of the helper functions which are handy for the model monitoring phase (i.e. after model implementation).

Usage

encode.woe(x, mapping)

Arguments

x

Character vector to be re-coded.

mapping

Data frame with compulsory columns: x.mod and x.woe which represents the mapping scheme. Column x.mod should contain unique values of original vector x, while x.woe should contain corresponding mapping values.

Value

The command encode.woe returns vector of re-coded WoE values.

Examples

suppressMessages(library(PDtoolkit))
data(gcd)
mbin <- cum.bin(x = gcd$maturity, y = gcd$qual, sc.method = "together")
mbin[[1]]
table(mbin[[2]], useNA = "always")
gcd$x.mod <- mbin[[2]]
woe.rep <- replace.woe(db = gcd[, c("qual", "x.mod")], target = "qual")
gcd$x.woe <- woe.rep[[1]]$x
mapping <- data.frame(x.mod = gcd$x.mod, x.woe = gcd$x.woe)%>%
     group_by(x.mod, x.woe) %>%
     summarise(n = n(), .groups = "drop")
mapping <- data.frame(mapping[, -3])
ewoe <- encode.woe(x = gcd$x.mod, mapping = mapping)
identical(ewoe, woe.rep[[1]]$x)

[Package PDtoolkit version 1.2.0 Index]