| scr_sql | R Documentation |
Code ready to run in the database, covering exactly the approved variables (or those of the scorecard), in blocks in this order:
scr_sql(x, table = NULL, dialect = NULL, file = NULL, ...)
## S3 method for class 'scr_capital'
scr_sql(
x,
table = NULL,
dialect = NULL,
file = NULL,
level = c("exposure", "portfolio"),
...
)
## S3 method for class 'scr_ead'
scr_sql(x, table = NULL, dialect = NULL, file = NULL, ...)
## S3 method for class 'scr_lgd'
scr_sql(x, table = NULL, dialect = NULL, file = NULL, ...)
## S3 method for class 'scr_pd'
scr_sql(x, table = NULL, dialect = NULL, file = NULL, ...)
## S3 method for class 'scr_result'
scr_sql(x, table = NULL, dialect = NULL, file = NULL, output = NULL, ...)
## S3 method for class 'scr_scorecard'
scr_sql(
x,
table = NULL,
dialect = NULL,
file = NULL,
what = c("score", "woe", "all"),
keep_columns = NULL,
...
)
## S3 method for class 'scr_study'
scr_sql(
x,
table = NULL,
dialect = NULL,
file = NULL,
score = "score",
numbered = TRUE,
...
)
x |
An object from |
table |
Source table name, written verbatim (it may be qualified,
|
dialect |
Dialect ( |
file |
Path to write to. |
... |
Passed on to the methods. |
level |
For |
output |
For |
what |
For |
keep_columns |
For |
score |
For |
numbered |
For a tiers study: |
CTE base_scr: reproduces the Stage 1 pre-processing -
imputation of missing and sentinel by the training median,
special-population flags, COALESCE of the categorical missing.
The WOE/BIN transformation, emitted by
OptimalBinningWoE::obwoe_sql() from the authoritative cut points
with full precision.
(Scorecard) CTE woe_scr with WOE and bin index, followed by the
final SELECT with score (exact, a + b * logit), <f>_points
per variable and score_points (whole points).
The order matters: without the first block, the WOE would be applied to
data different from what was binned. Column names are quoted with the
dialect's delimiters only when they are not plain identifiers or are
reserved words, the same rule OptimalBinningWoE::obwoe_sql() applies,
so every block names a column the same way. A row whose value falls in
no fitted bin (a category never seen on train) takes a WOE of 0 and the
points of a WOE of 0, in the SQL as in scr_apply(). The score computed by the SQL
matches scr_apply() numerically, by an automated test that runs both
paths.
A character vector with the SQL (invisibly, when file is given).
scr_pd wraps the scorecard SQL in a common table expression and adds a
CASE on the score cut points that yields grade and pd_final.
scr_lgd chains the driver bins of both stages, the logits, the pool
CASE and the floored result. scr_ead computes the utilization and the
undrawn amount, assigns the pool from the frozen cut points and applies
the greatest of the model, the drawn amount and the standardized floor.
scr_capital carries the constants of every pool (PD, LGD, k, risk
weight) in a pool_params table joined on segment and grade, so no
normal quantile is evaluated at run time; level chooses the exposure
or the portfolio output.
For a score study (scr_bands(), scr_tiers()), the SQL reads the score
column of table and adds tier and tier_label with a CASE on the
frozen cuts (score >= cut is the upper side; a NULL score gives a
NULL tier). table and dialect default to the configuration of the
scorecard the study came from, else to "your_table" and "ansi". The
tiers computed by the SQL match scr_apply(), by an automated test.
The labels of a tiers study carry their order, '01.very high' for the
tier with the highest event rate down to the tier with the lowest, as in
scr_apply(), so ORDER BY tier_label lists the event-richest tier
first; numbered = FALSE emits the plain labels. Band labels are
intervals and never get a prefix.
Other production:
predict.scr_align(),
scr_apply(),
scr_export(),
scr_monitor(),
scr_monitoring_plan(),
scr_reasons()
cfg <- scr_config(verbose = FALSE, nthread = 1, use_ranger = FALSE,
xgb_rounds = 60, n_boot = 20)
res <- scr_select(scr_demo, "default", config = cfg, drop = "id",
date_col = "ref_date")
cat(head(scr_sql(res, table = "prd.customers", dialect = "databricks"), 20), sep = "\n")
sc <- scr_scorecard(res)
cat(tail(scr_sql(sc), 12), sep = "\n")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.