BinProfet: Binning Variable(s)

Description Usage Arguments Details Value Examples

View source: R/Rprofet.R

Description

Function that bins selected variable(s) and returns a dataframe with binned values. Uses greedy binning algorithm to perform coarse binning of selected variable(s).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
BinProfet(
  dat,
  id,
  target,
  varcol,
  minimum.cat = 4,
  num.bins = 10,
  min.pts.bin = 25,
  bracket = "left",
  special.values = NULL
)

Arguments

dat

Dataframe of that contains ID, binary target and variables to be binned.

id

ID variable. See 'Details'.

target

The binary taget/response variable for WOE. See 'Details'.

varcol

Vector of variables to be binned.

minimum.cat

Minimum number of bins.

num.bins

Target number of bins. Overridden by the number of levels if varcol is factor.

min.pts.bin

Minimum number of observations in a bin.

bracket

Indicating if the intervals should be closed on the right or left. Options include left and right.

special.values

A vector of values that should have their own bin. See 'Details'.

Details

The id and the target variables must be provided. Works for numeric, factor and binary target. To build a scorecard, a binary target is required.

Actual number of bins exceeds num.bins if special.values specified.

Value

A dataframe containing the ID, target, and binned variable(s) with corresponding binned vlues.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
mydata <- ISLR::Default
head(mydata)

mydata$ID <- seq(1:nrow(mydata)) ## make an ID variable
mydata$default <- ifelse(mydata$default=="Yes", 1, 0) ## target coded with 1, 0

## bin balance and income
binned1 <- BinProfet(mydata, id="ID", target="default",
                  varcol = c("balance",  "income"), num.bins = 5)
head(binned1)

## bin categorical variable-------------------
binned2 <- BinProfet(mydata, id="ID", target="default",
                   varcol = "student", num.bins = 5)
head(binned2)
summary(binned2$student_Bins) ## num.bins overriden

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

Related to BinProfet in Rprofet...