gini_table: Performance measure table with Gini coefficient,...

Description Usage Arguments Value Author(s) Examples

View source: R/functions.R

Description

The function takes a dataframe along with a model or the name of a column with predicted value. If a model (only lm or glm works is guaranted to work perfectly) is provided as argument, the response on the data is predicted. Otherwise, if the data already contains a predicted column, it can be referred as an argument. The predicted column, thus obtained, is classified into bands to get the Gini coefficient, Kolmogorov-Smirnov statistics and Gini lift curve. The number of bands required can be passed as argument, with default value as 10 ie. decile binning is done. Otherwise, the cutpoints for converting the predicted value into bands can also be specified.

Usage

1
2
gini_table(base, target, col_pred = F, model = F, brk = F,
  quantile_pt = 10, event_rate_direction = "decreasing")

Arguments

base

input dataframe

target

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

col_pred

(optional) column name which contains the predicted value, not required if "model"=TRUE (default value is FALSE)

model

(optional) object of type lm or glm model, required only if "col_pred"=FALSE (default value is FALSE)

brk

(optional) array of break points of predicted value (default value is FALSE)

quantile_pt

(optional) number of quantiles to divide the predicted value range (default value is 10)

event_rate_direction

(optional) directionality of event rate with increasing value of predicted column, to be chosen among "increasing" or "decreasing" (default value is decreasing)

Value

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

prediction

base with the predicted value as a dataframe

gini_tab

gini table as a dataframe

gini_value

gini coefficient value

gini_plot

gini curve plot

ks_value

Kolmogorov-Smirnov statistic

breaks

break points

Author(s)

Arya Poddar <aryapoddar290990@gmail.com>

Aiana Goyal <aianagoel002@gmail.com>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
data <- iris
data$Species <- as.character(data$Species)
suppressWarnings(RNGversion('3.5.0'))
set.seed(11)
data$Y <- sample(0:1,size=nrow(data),replace=TRUE)
suppressWarnings(RNGversion('3.5.0'))
set.seed(11)
data$Y_pred <- sample(300:900,size=nrow(data),replace=TRUE)
gini_tab_list <- gini_table(base = data,target = "Y",col_pred = "Y_pred",quantile_pt = 10)
gini_tab_list$prediction
gini_tab_list$gini_tab
gini_tab_list$gini_value
gini_tab_list$gini_plot
gini_tab_list$ks_value
gini_tab_list$breaks

Example output

    Target predicted      band
1        0       466 (452,499]
2        0       300 [300,373]
3        1       606 (602,658]
4        0       308 [300,373]
5        0       338 [300,373]
6        1       873 (789,896]
7        0       351 [300,373]
8        0       474 (452,499]
9        1       829 (789,896]
10       0       374 (373,420]
11       0       405 (373,420]
12       0       564 (560,602]
13       1       845 (789,896]
14       1       811 (789,896]
15       1       741 (717,789]
16       1       644 (602,658]
17       0       589 (560,602]
18       0       498 (452,499]
19       0       394 (373,420]
20       0       588 (560,602]
21       0       422 (420,452]
22       1       708 (658,717]
23       0       518 (499,560]
24       0       510 (499,560]
25       0       337 [300,373]
26       0       590 (560,602]
27       0       539 (499,560]
28       0       309 [300,373]
29       0       375 (373,420]
30       0       539 (499,560]
31       1       603 (602,658]
32       0       496 (452,499]
33       0       547 (499,560]
34       0       421 (420,452]
35       1       788 (717,789]
36       1       685 (658,717]
37       0       466 (452,499]
38       0       362 [300,373]
39       0       453 (452,499]
40       0       334 [300,373]
41       0       448 (420,452]
42       0       429 (420,452]
43       0       596 (560,602]
44       1       692 (658,717]
45       0       497 (452,499]
46       1       819 (789,896]
47       1       683 (658,717]
48       0       308 [300,373]
49       1       618 (602,658]
50       1       801 (789,896]
51       1       602 (560,602]
52       1       659 (658,717]
53       0       555 (499,560]
54       0       487 (452,499]
55       0       433 (420,452]
56       0       566 (560,602]
57       0       547 (499,560]
58       1       790 (789,896]
59       0       397 (373,420]
60       1       658 (602,658]
61       0       380 (373,420]
62       1       752 (717,789]
63       0       404 (373,420]
64       1       648 (602,658]
65       1       751 (717,789]
66       0       409 (373,420]
67       0       334 [300,373]
68       0       599 (560,602]
69       0       415 (373,420]
70       1       672 (658,717]
71       1       712 (658,717]
72       0       555 (499,560]
73       0       556 (499,560]
74       0       422 (420,452]
75       1       864 (789,896]
76       1       621 (602,658]
77       0       462 (452,499]
78       0       499 (499,560]
79       0       518 (499,560]
80       0       432 (420,452]
81       0       330 [300,373]
82       0       598 (560,602]
83       1       605 (602,658]
84       0       441 (420,452]
85       1       789 (717,789]
86       0       551 (499,560]
87       0       415 (373,420]
88       1       689 (658,717]
89       1       788 (717,789]
90       0       435 (420,452]
91       0       519 (499,560]
92       1       759 (717,789]
93       0       308 [300,373]
94       0       586 (560,602]
95       1       787 (717,789]
96       0       443 (420,452]
97       1       760 (717,789]
98       0       416 (373,420]
99       1       652 (602,658]
100      0       434 (420,452]
101      1       771 (717,789]
102      1       706 (658,717]
103      0       545 (499,560]
104      0       545 (499,560]
105      0       424 (420,452]
106      0       458 (452,499]
107      1       715 (658,717]
108      1       744 (717,789]
109      1       638 (602,658]
110      0       385 (373,420]
111      1       724 (717,789]
112      0       354 [300,373]
113      0       563 (560,602]
114      1       794 (789,896]
115      1       702 (658,717]
116      0       481 (452,499]
117      1       859 (789,896]
118      0       569 (560,602]
119      1       614 (602,658]
120      0       447 (420,452]
121      0       418 (373,420]
122      0       473 (452,499]
123      1       895 (789,896]
124      0       402 (373,420]
125      0       571 (560,602]
126      0       343 [300,373]
127      0       315 [300,373]
128      1       814 (789,896]
129      1       723 (717,789]
130      1       679 (658,717]
131      1       873 (789,896]
132      1       709 (658,717]
133      0       428 (420,452]
134      1       615 (602,658]
135      0       384 (373,420]
136      0       589 (560,602]
137      0       463 (452,499]
138      1       726 (717,789]
139      1       765 (717,789]
140      1       896 (789,896]
141      1       705 (658,717]
142      1       635 (602,658]
143      0       570 (560,602]
144      1       713 (658,717]
145      0       433 (420,452]
146      1       617 (602,658]
147      1       654 (602,658]
148      0       498 (452,499]
149      1       821 (789,896]
150      0       482 (452,499]
   Lower_open_bound Upper_closed_bound      Band Total Non_event Event
11                0                  0      <NA>     0         0     0
1              [300                373 [300,373]    15        15     0
2               373                420 (373,420]    15        15     0
3               420                452 (420,452]    15        15     0
4               452                499 (452,499]    15        15     0
5               499                560 (499,560]    15        15     0
6               560                602 (560,602]    15        14     1
7               602                658 (602,658]    15         0    15
8               658                717 (658,717]    15         0    15
9               717                789 (717,789]    15         0    15
10              789                896 (789,896]    15         0    15
   Event_rate Cuml_non_event Cuml_event Pop_perc Cuml_non_event_perc
11 0.00000000              0          0      0.0           0.0000000
1  0.00000000             15          0      0.1           0.1685393
2  0.00000000             30          0      0.1           0.3370787
3  0.00000000             45          0      0.1           0.5056180
4  0.00000000             60          0      0.1           0.6741573
5  0.00000000             75          0      0.1           0.8426966
6  0.06666667             89          1      0.1           1.0000000
7  1.00000000             89         16      0.1           1.0000000
8  1.00000000             89         31      0.1           1.0000000
9  1.00000000             89         46      0.1           1.0000000
10 1.00000000             89         61      0.1           1.0000000
   Cuml_event_perc       Diff GINI_formula
11      0.00000000  0.0000000           NA
1       0.00000000 -0.1685393  0.000000000
2       0.00000000 -0.3370787  0.000000000
3       0.00000000 -0.5056180  0.000000000
4       0.00000000 -0.6741573  0.000000000
5       0.00000000 -0.8426966  0.000000000
6       0.01639344 -0.9836066  0.001289372
7       0.26229508 -0.7377049  0.000000000
8       0.50819672 -0.4918033  0.000000000
9       0.75409836 -0.2459016  0.000000000
10      1.00000000  0.0000000  0.000000000
[1] -0.9974213
[1] 0
 [1] 300.0 372.8 420.4 451.5 498.6 559.5 602.4 658.3 716.6 789.1 896.0

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