Skip to contents

Native CART classification tree, grown exactly as rpart::rpart grows a method = "class" tree with cp = 0, minsplit = 2, minbucket = 1, xval = 0 and the default priors (class frequencies), loss (0-1), maxcompete = 4, maxsurrogate = 5, usesurrogate = 2 and surrogatestyle = 0: Gini (or information) improvement split search over the midpoints between distinct values, rpart's cost-complexity bookkeeping (a split whose subtree does not lower the misclassification risk is collapsed), surrogate splits for missing values, and rpart's variable importance (primary improvement plus improvement times adjusted agreement for every surrogate). Returns the root split structure and normalised feature importances.

Usage

morie_decision_tree_split(x, y, criterion = "gini", max_depth = 30L, seed = 0L)

Arguments

x

Numeric predictor matrix.

y

Response (factor for classification).

criterion

"gini" or "entropy"; "entropy" uses rpart's "information" splitting index.

max_depth

Max tree depth (1 to 30, as in rpart).

seed

RNG seed (kept for API compatibility; the tree is deterministic).

Value

Named list: estimate, train_accuracy, root_feature, root_threshold, root_impurity, n_leaves, feature_importances, criterion, n, method.

Examples

set.seed(1)
x <- matrix(rnorm(120), 60, 2)
y <- factor(ifelse(x[, 1] > 0, "pos", "neg"))
morie_decision_tree_split(x, y)
#> $estimate
#> [1] 1
#> 
#> $train_accuracy
#> [1] 1
#> 
#> $root_feature
#> [1] 0
#> 
#> $root_threshold
#> [1] 0.02918736
#> 
#> $root_impurity
#> [1] 0.4994444
#> 
#> $n_leaves
#> [1] 2
#> 
#> $feature_importances
#> [1] 0.8787879 0.1212121
#> 
#> $criterion
#> [1] "gini"
#> 
#> $n
#> [1] 60
#> 
#> $method
#> [1] "Decision tree (CART, gini)"
#>