Predict terminal-node outcome means from a greedy CI tree
Source:R/predict_ci_tree_terminal_mean.R
predict_ci_tree_terminal_mean.RdAssigns training observations to terminal nodes, computes a weighted mean
outcome in each node, and returns those node means for new_data. This is a
simple prediction rule for scoring ci_tree() models when the tree itself
is primarily grown to reduce within-node inequality rather than prediction
error.
Usage
predict_ci_tree_terminal_mean(
fit,
train_data,
new_data = train_data,
outcome_name,
weights = NULL
)
predict_ctree_ci_terminal_mean(...)Arguments
- fit
A fitted
ci_treeor other object inheriting fromparty.- train_data
Training data used to compute terminal-node means.
- new_data
Data for which predictions should be returned. Defaults to
train_data.- outcome_name
Name of the numeric or logical outcome column in
train_data.- weights
Optional non-negative training weights.
- ...
Arguments passed to
predict_ci_tree_terminal_mean().
Value
A numeric vector of predicted terminal-node means.
A numeric vector of predicted terminal-node means.
Examples
toy_data <- data.frame(
rank = c(10, 20, 30, 40, 50, 60),
outcome = c(1, 0, 1, 0, 1, 1),
income = c(2, 4, 6, 8, 10, 12)
)
fit <- ci_tree(
cbind(rank, outcome) ~ income,
data = toy_data,
rank_name = "rank",
outcome_name = "outcome",
control = ci_tree_control(minsplit = 1, minbucket = 1, maxdepth = 1)
)
predict_ci_tree_terminal_mean(fit, toy_data, outcome_name = "outcome")
#> [1] 0.6 0.6 0.6 0.6 0.6 1.0