View source: R/best_cut_node.R
best.cut.node | R Documentation |
A function to select the splitting variables and nodes using one of four criteria.
best.cut.node(
X,
y,
Xsplit = X,
split,
lambda = "log",
weights = 1,
MinLeaf = 10,
numLabels = ifelse(split %in% c("gini", "entropy"), length(unique(y)), 0),
glmnetParList = NULL
)
X |
An n by d numeric matrix (preferable) or data frame. |
y |
A response vector of length n. |
Xsplit |
Splitting variables used to construct linear model trees. The default value is NULL and is only valid when split="linear". |
split |
The criterion used for splitting the nodes. "entropy": information gain and "gini": gini impurity index for classification; "": mean square error for regression; "linear": mean square error for multiple linear regression. |
lambda |
The argument of |
weights |
A vector of values which weigh the samples when considering a split. |
MinLeaf |
Minimal node size (Default 10). |
numLabels |
The number of categories. |
glmnetParList |
List of parameters used by the functions |
A list which contains:
BestCutVar: The best split variable.
BestCutVal: The best split points for the best split variable.
BestIndex: Each variable corresponds to maximum decrease in gini impurity index, information gain, and mean square error.
fitL and fitR: The multivariate linear models for the left and right nodes after splitting are trained using the function glmnet
.
### Find the best split variable ###
# Classification
data(iris)
X <- as.matrix(iris[, 1:4])
y <- iris[[5]]
(bestcut <- best.cut.node(X, y, split = "gini"))
(bestcut <- best.cut.node(X, y, split = "entropy"))
# Regression
data(body_fat)
X <- body_fat[, -1]
y <- body_fat[, 1]
(bestcut <- best.cut.node(X, y, split = "mse"))
set.seed(10)
cutpoint <- 50
X <- matrix(rnorm(100 * 10), 100, 10)
age <- sample(seq(20, 80), 100, replace = TRUE)
height <- sample(seq(50, 200), 100, replace = TRUE)
weight <- sample(seq(5, 150), 100, replace = TRUE)
Xsplit <- cbind(age = age, height = height, weight = weight)
mu <- rep(0, 100)
mu[age <= cutpoint] <- X[age <= cutpoint, 1] + X[age <= cutpoint, 2]
mu[age > cutpoint] <- X[age > cutpoint, 1] + X[age > cutpoint, 3]
y <- mu + rnorm(100)
bestcut <- best.cut.node(X, y, Xsplit,
split = "linear",
glmnetParList = list(lambda = 0)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.