1 #' @include b_Algorithm.R
3 #' @title Regression Tree
5 #' @description Regression Tree using the \code{tree} package.
6 #' Inherits \code{\link{Algorithm}}
8 #' @field nleaf Number of leaf nodes after pruning. Default: Inf (no pruning)
10 RegressionTree = setRefClass(
11 Class = "RegressionTree",
17 contains = "Algorithm",
20 initialize = function(...)
23 if (length(nleaf) == 0 || nleaf < 1)
26 predict_noNA = function(XY, x)
28 require(tree, quietly=TRUE)
29 rt = tree(Measure ~ ., data=XY)
30 treeSize = sum( rt$frame[["var"]] == "<leaf>" )
32 rt = prune.tree(rt, best = nleaf)
33 return (stats::predict(rt, as.data.frame(x)))