This defines the method "predict" for objects of S4 class glmtree-class.
Usage
predict(object, ...)
# S4 method for class 'glmtree'
predict(object, newdata, type = c("response", "segment"), ...)Details
Applies the best tree to new observations to find their segment, then the logistic regression of that segment. Observations with a factor level not seen in training receive the rate of positives of their segment.
Examples
set.seed(1)
data <- generateData(n = 300, scenario = "tree")
fit <- glmtree(
x = data[, c("x1", "x2", "x3")], y = data$y, K = 5, iterations = 20,
ctree_controls = partykit::ctree_control(alpha = 0.1, minbucket = 30, maxdepth = 3)
)
table(predict(fit, data[, c("x1", "x2", "x3")], type = "segment"))
#>
#> 1 2 5
#> 85 72 143