I think I ran into a problem.
ignore this - if you customize your control with cp = 0, this will not happen. I think that if the first node of the tree does not improve (or at least not better than cp), the tree will remain with nodes 0, so you will have an empty tree, and this will lead to the algorithm crashing.
EDIT: the problem is that rpart generates trees with only one leaf (node), and the boosting method uses this clause "k <- varImp (arboles [[m]], surrogates = FALSE, competes = FALSE), being arbols [ [m]] a tree with only one node, it gives you eror.
To solve this problem, you can change the enhancement method:
Write: fix (increase) and add * lines.
if (boos == TRUE) { ** k <- 1 ** while (k == 1){ boostrap <- sample(1:n, replace = TRUE, prob = pesos) fit <- rpart(formula, data = data[boostrap, -1], control = control) ** k <- length(fit$frame$var) ** } flearn <- predict(fit, newdata = data[, -1], type = "class") ind <- as.numeric(vardep != flearn) err <- sum(pesos * ind) }
this will prevent the algorithm from using a single tree of trees, but you must set the CP from the control parameter to 0 to avoid an infinite loop.
source share