iv_table: WOE and IV table for list of numerical and categorical...

Description Usage Arguments Value Author(s) Examples

View source: R/functions.R

Description

The function takes column indices of categorical and numerical variables and returns a list with four dataframes - WOE table of numerical variables, categorical variables, consolidated table of both numerical & categorical variables and a IV table.

Usage

1
2
iv_table(base, target, num_var_name = F, num_missing = -99999,
  cat_var_name = F, mincriterion = 0.1, event = 1)

Arguments

base

input dataframe

target

column / field name for the target variable to be passed as string (must be 0/1 type)

num_var_name

column name or array of column names of numerical variable for which IV is to be calculated, to be passed as string

num_missing

(optional) imputed missing value for numerical variable or an array of values which are to be kept as different bucket in binning step (default value is -99999)

cat_var_name

column name or array of column names of categorical variable for which IV is to be calculated, to be passed as string

mincriterion

(optional) the value of the test statistic or (1 - p-value) that must be exceeded in order to implement a split (default value is 0.1)

event

(optional) the event class, to be passed as 0 or 1 (default is 1)

Value

An object of class "iv_table" is a list containing the following components:

num_woe_table

numerical woe table with IV as a dataframe

cat_woe_table

categorical woe table with IV as a dataframe

woe_table

numerical and categorical woe table with IV as a dataframe

iv_table

Variable with IV value as a dataframe

Author(s)

Arya Poddar <aryapoddar290990@gmail.com>

Aiana Goyal <aianagoel002@gmail.com>

Kanishk Dogar <kanishkd4@gmail.com>

Examples

1
2
3
4
5
6
7
8
9
data <- iris
data$Species <- as.character(data$Species)
data$Y <- sample(0:1,size=nrow(data),replace=TRUE)
x <- c("Sepal.Length","Sepal.Width","Petal.Length","Petal.Width")
iv_table_list <- iv_table(base = data,target = "Y",num_var_name = x,cat_var_name = "Species")
iv_table_list$num_woe_table
iv_table_list$cat_woe_table
iv_table_list$woe_table
iv_table_list$iv_table

Example output

   Variable_name Lower_open_bound Upper_closed_bound   Category Non_event Event
1   Sepal.Length             -Inf                5.4 (-Inf,5.4]        30    22
2   Sepal.Length              5.4                6.3  (5.4,6.3]        31    25
3   Sepal.Length              6.3                Inf  (6.3,Inf]        14    28
4   Sepal.Length               NA                 NA      Total        75    75
5    Sepal.Width             -Inf                3.2 (-Inf,3.2]        49    58
6    Sepal.Width              3.2                Inf  (3.2,Inf]        26    17
7    Sepal.Width               NA                 NA      Total        75    75
8   Petal.Length             -Inf                4.9 (-Inf,4.9]        55    49
9   Petal.Length              4.9                Inf  (4.9,Inf]        20    26
10  Petal.Length               NA                 NA      Total        75    75
11   Petal.Width             -Inf                0.6 (-Inf,0.6]        28    22
12   Petal.Width              0.6                1.7  (0.6,1.7]        27    27
13   Petal.Width              1.7                2.0    (1.7,2]        10    13
14   Petal.Width              2.0                Inf    (2,Inf]        10    13
15   Petal.Width               NA                 NA      Total        75    75
   Total Event_rate Non_event_perc Event_perc  Pop_perc        woe          iv
1     52  0.4230769      0.4000000  0.2933333 0.3466667  0.3101549 0.033083192
2     56  0.4464286      0.4133333  0.3333333 0.3733333  0.2151114 0.017208910
3     42  0.6666667      0.1866667  0.3733333 0.2800000 -0.6931472 0.129387474
4    150  0.5000000      1.0000000  1.0000000 1.0000000 -0.1678809 0.179679576
5    107  0.5420561      0.6533333  0.7733333 0.7133333 -0.1686227 0.020234725
6     43  0.3953488      0.3466667  0.2266667 0.2866667  0.4248832 0.050985983
7    150  0.5000000      1.0000000  1.0000000 1.0000000  0.2562605 0.071220709
8    104  0.4711538      0.7333333  0.6533333 0.6933333  0.1155129 0.009241031
9     46  0.5652174      0.2666667  0.3466667 0.3066667 -0.2623643 0.020989141
10   150  0.5000000      1.0000000  1.0000000 1.0000000 -0.1468514 0.030230172
11    50  0.4400000      0.3733333  0.2933333 0.3333333  0.2411621 0.019292965
12    54  0.5000000      0.3600000  0.3600000 0.3600000  0.0000000 0.000000000
13    23  0.5652174      0.1333333  0.1733333 0.1533333 -0.2623643 0.010494571
14    23  0.5652174      0.1333333  0.1733333 0.1533333 -0.2623643 0.010494571
15   150  0.5000000      1.0000000  1.0000000 1.0000000 -0.2835665 0.040282106
  Variable_name   Category Non_event Event Total Event_rate Non_event_perc
1       Species     setosa        28    22    50       0.44      0.3733333
2       Species versicolor        25    25    50       0.50      0.3333333
3       Species  virginica        22    28    50       0.56      0.2933333
4       Species      Total        75    75   150       1.50      1.0000000
  Event_perc  Pop_perc           woe         iv
1  0.2933333 0.3333333  2.411621e-01 0.01929296
2  0.3333333 0.3333333  0.000000e+00 0.00000000
3  0.3733333 0.3333333 -2.411621e-01 0.01929296
4  1.0000000 1.0000000 -5.551115e-17 0.03858593
   Variable_name   Category Non_event Event Total Event_rate Non_event_perc
1   Sepal.Length (-Inf,5.4]        30    22    52  0.4230769      0.4000000
2   Sepal.Length  (5.4,6.3]        31    25    56  0.4464286      0.4133333
3   Sepal.Length  (6.3,Inf]        14    28    42  0.6666667      0.1866667
4   Sepal.Length      Total        75    75   150  0.5000000      1.0000000
5    Sepal.Width (-Inf,3.2]        49    58   107  0.5420561      0.6533333
6    Sepal.Width  (3.2,Inf]        26    17    43  0.3953488      0.3466667
7    Sepal.Width      Total        75    75   150  0.5000000      1.0000000
8   Petal.Length (-Inf,4.9]        55    49   104  0.4711538      0.7333333
9   Petal.Length  (4.9,Inf]        20    26    46  0.5652174      0.2666667
10  Petal.Length      Total        75    75   150  0.5000000      1.0000000
11   Petal.Width (-Inf,0.6]        28    22    50  0.4400000      0.3733333
12   Petal.Width  (0.6,1.7]        27    27    54  0.5000000      0.3600000
13   Petal.Width    (1.7,2]        10    13    23  0.5652174      0.1333333
14   Petal.Width    (2,Inf]        10    13    23  0.5652174      0.1333333
15   Petal.Width      Total        75    75   150  0.5000000      1.0000000
16       Species     setosa        28    22    50  0.4400000      0.3733333
17       Species versicolor        25    25    50  0.5000000      0.3333333
18       Species  virginica        22    28    50  0.5600000      0.2933333
19       Species      Total        75    75   150  1.5000000      1.0000000
   Event_perc  Pop_perc           woe          iv
1   0.2933333 0.3466667  3.101549e-01 0.033083192
2   0.3333333 0.3733333  2.151114e-01 0.017208910
3   0.3733333 0.2800000 -6.931472e-01 0.129387474
4   1.0000000 1.0000000 -1.678809e-01 0.179679576
5   0.7733333 0.7133333 -1.686227e-01 0.020234725
6   0.2266667 0.2866667  4.248832e-01 0.050985983
7   1.0000000 1.0000000  2.562605e-01 0.071220709
8   0.6533333 0.6933333  1.155129e-01 0.009241031
9   0.3466667 0.3066667 -2.623643e-01 0.020989141
10  1.0000000 1.0000000 -1.468514e-01 0.030230172
11  0.2933333 0.3333333  2.411621e-01 0.019292965
12  0.3600000 0.3600000  0.000000e+00 0.000000000
13  0.1733333 0.1533333 -2.623643e-01 0.010494571
14  0.1733333 0.1533333 -2.623643e-01 0.010494571
15  1.0000000 1.0000000 -2.835665e-01 0.040282106
16  0.2933333 0.3333333  2.411621e-01 0.019292965
17  0.3333333 0.3333333  0.000000e+00 0.000000000
18  0.3733333 0.3333333 -2.411621e-01 0.019292965
19  1.0000000 1.0000000 -5.551115e-17 0.038585929
   Variable_name         iv
4   Sepal.Length 0.17967958
7    Sepal.Width 0.07122071
15   Petal.Width 0.04028211
19       Species 0.03858593
10  Petal.Length 0.03023017

scorecardModelUtils documentation built on May 2, 2019, 9:59 a.m.