View source: R/18_INTERACTION_TRANSFORMER.R
interaction.transformer | R Documentation |
interaction.transformer
extracts the interaction between supplied risk factors from decision tree.
It implements customized decision tree algorithm that takes into account different conditions such as minimum
percentage of observations and defaults in each node, maximum tree depth and monotonicity condition
at each splitting node. Gini index is used as metric for node splitting .
interaction.transformer(
db,
rf,
target,
min.pct.obs,
min.avg.rate,
max.depth,
monotonicity,
create.interaction.rf
)
db |
Data frame of risk factors and target variable supplied for interaction extraction. |
rf |
Character vector of risk factor names on which decision tree is run. |
target |
Name of target variable (default indicator 0/1) within db argument. |
min.pct.obs |
Minimum percentage of observation in each leaf. |
min.avg.rate |
Minimum percentage of defaults in each leaf. |
max.depth |
Maximum number of splits. |
monotonicity |
Logical indicator. If |
create.interaction.rf |
Logical indicator. If |
The command interaction.transformer
returns a list of two data frames. The first data frame provides
the tree summary. The second data frame is a new risk factor extracted from decision tree.
suppressMessages(library(PDtoolkit))
data(loans)
#modify risk factors in order to show how the function works with missing values
loans$"Account Balance"[1:10] <- NA
loans$"Duration of Credit (month)"[c(13, 15)] <- NA
it <- interaction.transformer(db = loans,
rf = c("Account Balance", "Duration of Credit (month)"),
target = "Creditability",
min.pct.obs = 0.05,
min.avg.rate = 0.01,
max.depth = 2,
monotonicity = TRUE,
create.interaction.rf = TRUE)
names(it)
it[["tree.info"]]
tail(it[["interaction"]])
table(it[["interaction"]][, "rf.inter"], useNA = "always")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.