# \donttest{
# =============================================================================
# Example 1: From obwoe Object (Standard Usage)
# =============================================================================
set.seed(42)
n <- 1000
df <- data.frame(
age = rnorm(n, 40, 15),
income = exp(rnorm(n, 10, 0.8)),
score = rnorm(n, 600, 100),
target = rbinom(n, 1, 0.15)
)
model <- obwoe(df, target = "target")
gains <- obwoe_gains(model, feature = "age")
print(gains)
# Access metrics
cat("KS:", gains$metrics$ks, "%\n")
cat("Gini:", gains$metrics$gini, "%\n")
# =============================================================================
# Example 2: From obwoe_apply Output - Using Bin Column
# =============================================================================
scored <- obwoe_apply(df, model)
# Default: uses age_bin column
gains_bin <- obwoe_gains(scored,
target = df$target, feature = "age",
use_column = "bin"
)
# =============================================================================
# Example 3: From obwoe_apply Output - Using WoE Column
# =============================================================================
# Group by WoE values (continuous analysis)
gains_woe <- obwoe_gains(scored,
target = df$target, feature = "age",
use_column = "woe", n_groups = 5
)
# =============================================================================
# Example 4: Any Variable - Score Decile Analysis
# =============================================================================
# Create score deciles manually
df$score_decile <- cut(df$score,
breaks = quantile(df$score, probs = seq(0, 1, 0.1)),
include.lowest = TRUE, labels = 1:10
)
# Analyze score deciles directly
gains_score <- obwoe_gains(df,
target = "target", feature = "score_decile",
use_column = "direct"
)
print(gains_score)
# =============================================================================
# Example 5: Automatic Decile Creation
# =============================================================================
# Use n_groups to automatically create quantile groups
gains_auto <- obwoe_gains(df,
target = "target", feature = "score",
use_column = "direct", n_groups = 10
)
# }
Run the code above in your browser using DataLab