WOE_customFactor: Custom Binning Factor Variables

Description Usage Arguments Value Examples

View source: R/Rprofet.R

Description

Function that bins a factor variable based on user inputted factor levels, plots the information on the new bins, and returns a vector of the newly binned values

Usage

1
WOE_customFactor(dataset, var, target, new_levels, color = "#0066CC")

Arguments

dataset

Dataframe containing the target variable and desired factor variables to be binned.

var

A specific factor attribute to be binned.

target

A binary target variable. Must be specified.

new_levels

A vector the same length as the number of levels for the categorical variable containing the new factor levels. Must be specified.

color

A hexadecimal value representing a specific color.

Value

A vector containing the newly binned values. Generates three barplots displaying the worth of evidence (WoE), target rate and frequency across all bins. The bars are arranged in an ascending order of WoE.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
mydata <- ISLR::Default
mydata$default <- ifelse(mydata$default=="Yes", 1, 0) ## target coded with 1, 0
## WOE_customFactor
custom1 <- WOE_customFactor(mydata, var="student", target="default",
                 new_levels=c("Student : No","Student : Yes"))
levels(custom1)
## --------------------------
mydata$balance_cat <- cut(mydata$balance, breaks = c(-1,400,800,1200,1600,2000,2400,2800),
                      labels = c("Very-Low","Low","Med-Low","Med","Med-High","High","Very-High"))
custom2 <- WOE_customFactor(mydata, var="balance_cat", target="default",
                   new_levels=c(1,1,2,2,2,3,3))
levels(custom2)

Rprofet documentation built on April 1, 2020, 5:11 p.m.