# Example: Binning a variable with a sigmoid relationship to target
set.seed(123)
n <- 1000
# Generate feature
feature <- rnorm(n)
# Generate target based on logistic probability
prob <- 1 / (1 + exp(-2 * feature))
target <- rbinom(n, 1, prob)
# Perform Optimal Binning
result <- ob_numerical_bb(feature, target,
min_bins = 3,
max_bins = 5,
is_monotonic = TRUE
)
# Check results
print(data.frame(
Bin = result$bin,
Count = result$count,
WoE = round(result$woe, 4),
IV = round(result$iv, 4)
))
cat("Total IV:", result$total_iv, "\n")
Run the code above in your browser using DataLab