gains_table
creates a data frame including distribution of total, negative, positive, positive rate and rejected rate by score bins. The gains table is used in conjunction with financial and operational considerations to make cutoff decisions.
gains_table(score, label, bin_num = 10, method = "freq", width_by = NULL,
breaks_by = NULL, positive = "bad|1", ...)
A list of credit score for actual and expected data samples. For example, score = list(actual = scoreA, expect = scoreE).
A list of label value for actual and expected data samples. For example, label = list(actual = labelA, expect = labelE).
Integer, the number of score bins. Defaults to 10. If it is 'max', then individual scores are used as bins.
The score is binning by equal frequency or equal width. Accepted values are 'freq' and 'width'. Defaults to 'freq'.
Number, increment of the score breaks when method is set as 'width'. If it is provided the above parameter bin_num will not be used. Defaults to NULL.
The name of data set to create breakpoints. Defaults to the first data set. Or numeric values to set breakpoints manually.
Value of positive class, Defaults to "bad|1".
Additional parameters.
A data frame
# \donttest{
# load germancredit data
data("germancredit")
# filter variable via missing rate, iv, identical value rate
dtvf = var_filter(germancredit, "creditability")
#> ℹ Filtering variables via missing_rate, identical_rate, info_value ...
#> ✔ 1 variables are removed via identical_rate
#> ✔ 6 variables are removed via info_value
#> ✔ Variable filtering on 1000 rows and 20 columns in 00:00:00
#> ✔ 7 variables are removed in total
# breaking dt into train and test
dt_list = split_df(dtvf, "creditability")
label_list = lapply(dt_list, function(x) x$creditability)
# binning
bins = woebin(dt_list$train, "creditability")
#> ℹ Creating woe binning ...
#> ✔ Binning on 681 rows and 14 columns in 00:00:00
# scorecard
card = scorecard2(bins, dt = dt_list$train, y = 'creditability')
# credit score
score_list = lapply(dt_list, function(x) scorecard_ply(x, card))
###### gains_table examples ######
# Example I, input score and label can be a vector or a list
g1 = gains_table(score = unlist(score_list), label = unlist(label_list))
g2 = gains_table(score = score_list, label = label_list)
# Example II, specify the bins number and type
g3 = gains_table(score = unlist(score_list), label = unlist(label_list), bin_num = 20)
g4 = gains_table(score = unlist(score_list), label = unlist(label_list), method = 'width')
# }