View source: R/34_DECISION_TREE.R
predict.cdt | R Documentation |
Predict method for custom decision tree
## S3 method for class 'cdt'
predict(object, newdata = NULL, ...)
object |
Custom decision tree model (class cdt). |
newdata |
Optionally, a data frame in which to look for variables with which to predict. If omitted, the fitted predictors are used. |
... |
further arguments passed to or from other methods. |
Returns average default rate per leaf.
#S3 method for class "cdt"
suppressMessages(library(PDtoolkit))
data(loans)
tree.res <- decision.tree(db = loans,
rf = c("Account Balance", "Duration of Credit (month)"),
target = "Creditability",
min.pct.obs = 0.05,
min.avg.rate = 0.01,
p.value = 0.05,
max.depth = NA,
monotonicity = TRUE)
str(tree.res)
#predict method - development sample
pred.1 <- predict(object = tree.res, newdata = NULL)
head(pred.1)
auc.model(predictions = pred.1$average, observed = loans$Creditability)
#predict method - new data
set.seed(321)
loans.m <- loans[sample(1:nrow(loans), 500, replace = TRUE), ]
pred.2 <- predict(object = tree.res, newdata = loans.m)
head(pred.2)
auc.model(predictions = pred.2$average, observed = loans.m$Creditability)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.