View source: R/03_WOE_BINNING.R
woe.bin | R Documentation |
woe.bin
implements extension of the three-stage monotonic binning procedure (iso.bin
)
with weights of evidence (WoE) threshold.
The first stage is isotonic regression used to achieve the monotonicity. The next two stages are possible corrections for
minimum percentage of observations and target rate, while the last stage is iterative merging of
bins until WoE threshold is exceeded.
woe.bin( x, y, sc = c(NA, NaN, Inf, -Inf), sc.method = "together", y.type = NA, min.pct.obs = 0.05, min.avg.rate = 0.01, woe.gap = 0.1, force.trend = NA )
x |
Numeric vector to be binned. |
y |
Numeric target vector (binary or continuous). |
sc |
Numeric vector with special case elements. Default values are |
sc.method |
Define how special cases will be treated, all together or in separate bins.
Possible values are |
y.type |
Type of |
min.pct.obs |
Minimum percentage of observations per bin. Default is 0.05 or minimum 30 observations. |
min.avg.rate |
Minimum |
woe.gap |
Minimum WoE gap between bins. Default is 0.1. |
force.trend |
If the expected trend should be forced. Possible values: |
The command woe.bin
generates a list of two objects. The first object, data frame summary.tbl
presents a summary table of final binning, while x.trans
is a vector of discretized values.
In case of single unique value for x
or y
of complete cases (cases different than special cases),
it will return data frame with info.
iso.bin
for three-stage monotonic binning procedure.
suppressMessages(library(monobin)) data(gcd) amount.bin <- woe.bin(x = gcd$amount, y = gcd$qual) amount.bin[[1]] diff(amount.bin[[1]]$woe) tapply(gcd$amount, amount.bin[[2]], function(x) c(length(x), mean(x))) woe.bin(x = gcd$maturity, y = gcd$qual)[[1]] woe.bin(x = gcd$maturity, y = gcd$qual, woe.gap = 0.5)[[1]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.