Skip to contents

J = (m_L/m) G_L + (m_R/m) G_R, with gini, entropy (log base 2) or mse impurity, plus the impurity decrease against the parent.

Usage

morie_geron_cart_split_cost(X, y, feature, threshold, criterion = "gini")

Arguments

X

Feature matrix.

y

Labels or targets.

feature

0-based column index, matching Python.

threshold

Split point; X[, feature] <= threshold goes left.

criterion

One of "gini", "entropy", "mse".

Value

List with cost, impurity_left, impurity_right, impurity_parent, impurity_decrease, n_left, n_right.

Examples

X <- matrix(c(1, 2, 3, 4), ncol = 1)
morie_geron_cart_split_cost(X, c(0, 0, 1, 1), 0, 1.5)
#> $cost
#> [1] 0.3333333
#> 
#> $impurity_left
#> [1] 0
#> 
#> $impurity_right
#> [1] 0.4444444
#> 
#> $impurity_parent
#> [1] 0.5
#> 
#> $impurity_decrease
#> [1] 0.1666667
#> 
#> $n_left
#> [1] 1
#> 
#> $n_right
#> [1] 3
#> 
#> $criterion
#> [1] "gini"
#> 
#> $threshold
#> [1] 1.5
#> 
#> $feature
#> [1] 0
#> 
#> $estimate
#> [1] 0.3333333
#> 
#> $n
#> [1] 4
#> 
#> $method
#> [1] "CART split cost"
#>