# \donttest{
# =============================================================================
# Example 1: Basic Usage - Train and Apply
# =============================================================================
set.seed(42)
n <- 1000
# Training data
train_df <- data.frame(
age = rnorm(n, 40, 15),
income = exp(rnorm(n, 10, 0.8)),
education = sample(c("HS", "BA", "MA", "PhD"), n, replace = TRUE),
target = rbinom(n, 1, 0.15)
)
# Fit binning model
model <- obwoe(train_df, target = "target")
# New data for scoring (could be validation/test set)
new_df <- data.frame(
age = c(25, 45, 65),
income = c(20000, 50000, 80000),
education = c("HS", "MA", "PhD")
)
# Apply transformations
scored <- obwoe_apply(new_df, model)
print(scored)
# Use WoE features for downstream modeling
woe_cols <- grep("_woe$", names(scored), value = TRUE)
print(woe_cols)
# =============================================================================
# Example 2: Without Original Features
# =============================================================================
scored_compact <- obwoe_apply(new_df, model, keep_original = FALSE)
print(scored_compact)
# }
Run the code above in your browser using DataLab