#' @title Classification Random Tree Learner
#' @author damirpolat
#' @name mlr_learners_classif.random_tree
#'
#' @description
#' Tree that considers K randomly chosen attributes at each node.
#' Calls [RWeka::make_Weka_classifier()] from \CRANpkg{RWeka}.
#'
#' @section Custom mlr3 parameters:
#' - `output_debug_info`:
#' - original id: output-debug-info
#'
#' - `do_not_check_capabilities`:
#' - original id: do-not-check-capabilities
#'
#' - `num_decimal_places`:
#' - original id: num-decimal-places
#'
#' - `batch_size`:
#' - original id: batch-size
#'
#' - Reason for change: This learner contains changed ids of the following control arguments
#' since their ids contain irregular pattern
#'
#'
#' @templateVar id classif.random_tree
#' @template learner
#'
#' @template seealso_learner
#' @template example
#' @export
LearnerClassifRandomTree = R6Class("LearnerClassifRandomTree",
inherit = LearnerClassif,
public = list(
#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
param_set = ps(
subset = p_uty(tags = "train"),
na.action = p_uty(tags = "train"),
K = p_int(default = 0L, lower = 0L, tags = "train"),
M = p_int(default = 1L, lower = 1L, tags = "train"),
V = p_dbl(default = 1e-3, tags = "train"),
S = p_int(default = 1L, tags = "train"),
depth = p_int(default = 0L, lower = 0L, tags = "train"),
N = p_int(default = 0L, lower = 0L, tags = "train"),
U = p_lgl(default = FALSE, tags = "train"),
B = p_lgl(default = FALSE, tags = "train"),
output_debug_info = p_lgl(default = FALSE, tags = "train"),
do_not_check_capabilities = p_lgl(default = FALSE,
tags = "train"),
num_decimal_places = p_int(default = 2L, lower = 1L,
tags = "train"),
batch_size = p_int(default = 100L, lower = 1L, tags = "train"),
options = p_uty(default = NULL, tags = "train")
)
super$initialize(
id = "classif.random_tree",
packages = "RWeka",
feature_types = c("logical", "integer", "numeric", "factor", "ordered"),
predict_types = c("response", "prob"),
param_set = param_set,
properties = c("missings", "multiclass", "twoclass"),
man = "mlr3extralearners::mlr_learners_classif.random_tree",
label = "Random Tree"
)
}
),
private = list(
.train = function(task) {
weka_learner = RWeka::make_Weka_classifier("weka/classifiers/trees/RandomTree")
pars = self$param_set$get_values(tags = "train")
rweka_train(task$data(), task$formula(), pars, weka_learner)
},
.predict = function(task) {
pars = self$param_set$get_values(tags = "predict")
newdata = ordered_features(task, self)
rweka_predict(newdata, pars, self$predict_type, self$model)
}
)
)
.extralrns_dict$add("classif.random_tree", LearnerClassifRandomTree)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.