predict.cdt {PDtoolkit}R Documentation

Predict method for custom decision tree

Description

Predict method for custom decision tree

Usage

## S3 method for class 'cdt'
predict(object, newdata = NULL, ...)

Arguments

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.

Value

Returns average default rate per leaf.

Examples

#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)

[Package PDtoolkit version 1.2.0 Index]