woebin_ply
converts original values of input data into woe or bin based on the binning information generated from woebin
.
woebin_ply(dt, bins, to = "woe", no_cores = 2, print_step = 0L,
replace_blank_inf = TRUE, ...)
A data frame.
Binning information generated from woebin
.
Converting original values to woe or bin. Defaults to woe.
Number of CPU cores for parallel computation. Defaults to 2, if it sets to NULL then 90 percent of total cpu cores will be used.
A non-negative integer. Defaults to 1. If print_step>0, print variable names by each print_step-th iteration. If print_step=0 or no_cores>1, no message is print.
Logical. Replace blank values with NA and infinite with -1. Defaults to TRUE. This argument should be the same with woebin
's.
Additional parameters.
A data frame with columns for variables converted into woe values.
# load germancredit data
data(germancredit)
# Example I
dt = germancredit[, c("creditability", "credit.amount", "purpose")]
# binning for dt
bins = woebin(dt, y = "creditability")
#> ℹ Creating woe binning ...
#> ✔ Binning on 1000 rows and 3 columns in 00:00:00
# converting to woe
dt_woe = woebin_ply(dt, bins=bins)
#> ℹ Converting into woe values ...
#> ✔ Woe transformating on 1000 rows and 2 columns in 00:00:00
str(dt_woe)
#> Classes ‘data.table’ and 'data.frame': 1000 obs. of 3 variables:
#> $ creditability : Factor w/ 2 levels "bad","good": 2 1 2 2 1 2 2 2 2 1 ...
#> $ credit.amount_woe: num 0.0337 0.3905 -0.2583 0.3905 0.3905 ...
#> $ purpose_woe : num -0.41 -0.41 0.28 0.28 0.28 ...
#> - attr(*, ".internal.selfref")=<externalptr>
# converting to bin
dt_bin = woebin_ply(dt, bins=bins, to = 'bin')
#> ℹ Converting into woe values ...
#> ✔ Woe transformating on 1000 rows and 2 columns in 00:00:00
str(dt_bin)
#> Classes ‘data.table’ and 'data.frame': 1000 obs. of 3 variables:
#> $ creditability : Factor w/ 2 levels "bad","good": 2 1 2 2 1 2 2 2 2 1 ...
#> $ credit.amount_bin: chr "[-Inf,1400)" "[4000,9200)" "[1800,4000)" "[4000,9200)" ...
#> $ purpose_bin : chr "radio/television" "radio/television" "furniture/equipment%,%domestic appliances%,%business%,%repairs%,%car (new)%,%others%,%education" "furniture/equipment%,%domestic appliances%,%business%,%repairs%,%car (new)%,%others%,%education" ...
#> - attr(*, ".internal.selfref")=<externalptr>
# \donttest{
# Example II
# binning for germancredit dataset
bins_germancredit = woebin(germancredit, y="creditability")
#> ℹ Creating woe binning ...
#> ✔ Binning on 1000 rows and 21 columns in 00:00:00
# converting the values in germancredit to woe
# bins is a list which generated from woebin()
germancredit_woe = woebin_ply(germancredit, bins_germancredit)
#> ℹ Converting into woe values ...
#> ✔ Woe transformating on 1000 rows and 20 columns in 00:00:00
# bins is a data frame
bins_df = data.table::rbindlist(bins_germancredit)
germancredit_woe = woebin_ply(germancredit, bins_df)
#> ℹ Converting into woe values ...
#> ✔ Woe transformating on 1000 rows and 20 columns in 00:00:00
# }