| scr_bands | R Documentation |
Cuts the score into bands of equal share (or into tail percentiles) frozen on the reference sample, and reads every band on the reference and on the study samples: volume, event rate with a Jeffreys interval, lift, capture (recall), the cumulative non-event share (false positive rate), KS, the band WOE and IV, odds, the PSI term against the reference and a one-sided Fisher exact test of rank order against the previous band. The summary adds the AUC, Gini and KS of every sample with a bootstrap interval.
scr_bands(x, ...)
## S3 method for class 'scr_scorecard'
scr_bands(
x,
n_bands = NULL,
spacing = c("uniform", "tail"),
tail_probs = NULL,
sample = "holdout",
reference = "train",
breaks = NULL,
level = NULL,
n_boot = NULL,
seed = NULL,
max_cells = 1e+05,
boot_cells = 10000,
...
)
## S3 method for class 'data.frame'
scr_bands(
x,
score = "score",
y = "y",
objective = "risk",
direction = NULL,
weight = NULL,
value = NULL,
sample = NULL,
reference = NULL,
study = NULL,
counts = FALSE,
n = "n",
events = "events",
n_bands = 20L,
spacing = c("uniform", "tail"),
tail_probs = NULL,
breaks = NULL,
level = 0.95,
n_boot = 200L,
seed = NULL,
max_cells = 1e+05,
value_events = NULL,
boot_cells = 10000,
...
)
x |
An object from |
... |
Passed on to the methods; an unknown argument is an error. |
n_bands |
Number of equal-share bands. For a scorecard, |
spacing |
|
tail_probs |
Cumulative shares from the event-rich side for
|
sample |
For a scorecard: the study sample(s), |
reference |
For a scorecard: the sample the bands are frozen on
( |
breaks |
Explicit ascending cut points; overrides |
level |
Confidence level of the intervals. For a scorecard, |
n_boot |
Bootstrap resamples of the AUC interval ( |
seed |
Seed of the bootstrap. A number is local to the call (the
user's random stream is restored on exit); |
max_cells |
Largest number of distinct score values kept exactly. |
boot_cells |
Largest number of score cells resampled exactly by the
bootstrap (default 10,000; |
score, y |
Column names of the score and of the 0/1 outcome ( |
objective |
|
direction |
|
weight |
Optional column of non-negative case weights. |
value |
Optional column of a value per case (an amount, a balance):
adds the value captured per band. With |
study |
Labels of the study samples; |
counts |
|
n, events |
Column names of the counts when |
value_events |
With |
An object of class c("scr_study_bands", "scr_study", "list"):
tableOne row per sample and band, event-richest band first:
sample, band, label, score_lo, score_hi, n, pct,
cum_pct, events, rate, rate_lo, rate_hi, cum_rate,
lift, lift_lo, lift_hi, cum_lift, capture,
cum_nonevent_pct, ks, pct_event, pct_nonevent, woe, iv,
odds, log_odds, psi, p_reversal, p_reversal_adj and, with
value, value, value_events, value_capture (cumulative share
of the event value) and value_precision (cumulative event value
over cumulative value).
summaryOne row per sample: sample, n, events, rate,
auc, auc_lo, auc_hi, gini, gini_lo, gini_hi, ks, iv,
psi (against the reference), n_bands_requested,
n_bands_effective and reversals (bands with p_reversal_adj
below 0.05).
cutsThe ascending cut points.
codes, code_labelsBand number and label of every interval
in ascending score order, used by scr_apply() and scr_sql().
objective, direction, level, spacing, reference,
samples, target, callThe settings.
n_bands_requested, n_bands_effective, quantized, histThe band counts, whether the scores were pooled, and the count table the study was computed from.
The scored rows are aggregated once into a table of counts per distinct
score (per sample); every statistic is then computed from that table, so
the cost is one pass over the rows plus work proportional to the number
of distinct scores. With more than max_cells distinct scores, the
scores are first pooled into max_cells cells of equal weighted share.
The cut targets are cumulative shares counted from the event-rich side
of the score (the high scores under higher_is_riskier, the low ones
under higher_is_safer): k / n_bands with spacing = "uniform", or
the shares in tail_probs with spacing = "tail" (default 0.1%, 0.5%,
1%, 2%, 5%, 10%, 20% and 50%). Each cut is placed midway between two
adjacent distinct reference scores, at the boundary nearest to its
target, so a group of tied scores is never split and a target is hit
within the share of one score value. Targets that land on the same
boundary give one cut: n_bands_effective can be smaller than
n_bands_requested, and both are reported. A band is left-closed,
[lo, hi): score >= cut is the upper side, the convention of
scr_cutoff(). breaks given explicitly are used as they are; the bands
of scr_score_gains() (breaks = sc$breaks) are right-closed, so a
score equal to a break falls one band higher here.
The band table lists the event-richest band first (band = 1). With
e_b events and m_b non-events in band b, totals E
and M, and overall rate R:
rate = e_b / (e_b + m_b), with the Jeffreys interval
rate_lo, rate_hi: the Beta(e_b + 1/2, m_b + 1/2) quantiles,
0 and 1 at the edges (Brown, Cai and DasGupta, 2001). Under weights,
the counts are scaled to the Kish effective size
(\sum w)^2 / \sum w^2.
lift = rate / R (its interval divides the rate bounds by
R); cum_rate and cum_lift accumulate from the first band.
capture = \sum_{j \le b} e_j / E (recall),
cum_nonevent_pct = \sum_{j \le b} m_j / M (false positive
rate) and ks their absolute difference.
pct_event, pct_nonevent and woe = \ln(e_b / E) -
\ln(m_b / M) as in scr_strategy() (0.5 is added to every band only
when a band lacks events or non-events); iv =
(pct_event - pct_nonevent) * woe.
odds and log_odds in the orientation of the scale
(non-events per event under higher_is_safer, events per non-event
under higher_is_riskier, 0.5 added to each count), as in
scr_score_gains().
psi: the band term of the PSI against the reference shares
(see scr_psi()); NA on the reference itself.
p_reversal: one-sided Fisher exact test that the band has a
higher event rate than the previous, event-richer band (a
reversal of the rank order); p_reversal_adj is Holm-adjusted over
the bands of the sample. The tests use the unweighted counts.
Rows with a missing or infinite score, or a zero weight, are not counted;
rows with a missing outcome count in the volume (n, pct, the PSI) but
not in the rates.
The bootstrap of the AUC draws the event and non-event counts of every
score value from multinomial laws with the observed shares (the law of a
row bootstrap stratified by outcome), with the unweighted class counts as
sizes; a given seed is local to the call, while seed = NULL draws
from, and advances, the user's random stream. Up to boot_cells cells of
the count table the bootstrap is exact. Above it, the resamples run on
boot_cells cells of equal share (adjacent cells pooled) and are shifted
to the point estimate of the full table, so the interval is an
approximation. The point estimates use every cell of the count table:
every distinct score, unless max_cells pooled the scores into cells.
boot_cells = Inf keeps the bootstrap exact, at a cost per resample
proportional to the number of cells.
Brown, L. D., Cai, T. T. and DasGupta, A. (2001). Interval estimation for a binomial proportion. Statistical Science, 16(2), 101-133. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1214/ss/1009213286")}
DeLong, E. R., DeLong, D. M. and Clarke-Pearson, D. L. (1988). Comparing the areas under two or more correlated receiver operating characteristic curves: a nonparametric approach. Biometrics, 44(3), 837-845.
Siddiqi, N. (2006). Credit Risk Scorecards: Developing and Implementing Intelligent Credit Scoring. Wiley.
Yurdakul, B. and Naranjo, J. (2020). Statistical properties of the population stability index. Journal of Risk Model Validation, 14(4), 89-100.
scr_tiers() for a small number of policy tiers, scr_rag()
for traffic lights, scr_apply() and scr_sql() to assign the bands in
production.
Other score-studies:
scr_claims(),
scr_detection(),
scr_maturity(),
scr_mix_shift(),
scr_operating(),
scr_overlap(),
scr_rag(),
scr_rag_plan(),
scr_score_cross(),
scr_segments(),
scr_tiers(),
scr_uplift()
cfg <- scr_config(verbose = FALSE, nthread = 1, use_ranger = FALSE,
use_lightgbm = FALSE, xgb_rounds = 40, n_boot = 20)
res <- scr_select(scr_demo, "default", config = cfg, drop = c("id", "churn"),
date_col = "ref_date")
sc <- scr_scorecard(res)
b <- scr_bands(sc, n_bands = 10)
b
b$table[sample == "holdout", .(band, label, n, rate, lift, capture, ks)]
# tail percentiles, from a data.frame
d <- data.frame(score = sc$samples$holdout$score, y = sc$samples$holdout$y)
scr_bands(d, spacing = "tail", n_boot = 0)$table[, .(band, label, pct, rate, capture)]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.