Function that bins a numeric variable based on user inputted breaks, plots the information on the new bins, and returns a list contains a dataframe of the newly binned values and id column and more items.
WOE_customNum(
data,
var,
id,
target,
breaks,
right_bracket = F,
color = "#0066CC",
plot = FALSE
)
A list with the following components.
Dataframe with the binned variable.
Dataframe with target, binned variable, and WOE values for the bins.
Information value of the newly binned variable.
Dataframe with binned variable, WOE values for the bins, Target Rate for each bin, and observation count for each bin.
Dataframe containing the target variable and desired numeric variables to be binned.
A specific numeric attribute to be binned. Must be specified.
The unique id variable in the dataframe. Must be specified.
A binary target variable. Must be specified.
A vector of breakpoints for the desired bins. Must be specified.
Logical. Specifying whether the intervals are closed on the right or the left.
A hexadecimal value representing a specific color.
Logical. The default is FALSE which does not generate the plots.
mydata <- ISLR::Default
mydata$ID = seq(1:nrow(mydata)) ## make the ID variable
mydata$default <- ifelse(mydata$default=="Yes", 1, 0) ## target coded with 1, 0
WC_1 <- WOE_customNum(data= mydata, var="balance", id= "ID", target = "default",
breaks= seq(0,3000,1000))
head(WC_1$NewBin)
head(WC_1$BinWOE)
WC_1$IV
WC_1$vars
WC_2 <- WOE_customNum(data= mydata, var="income", id= "ID", target = "default",
breaks=seq(0,75000, 15000))
head(WC_2$NewBin)
head(WC_2$BinWOE)
WC_2$IV
WC_2$vars
Run the code above in your browser using DataLab