Skip to content

Commit

Permalink
Update {regr,classif}.ranger learner for 0.17.0 (#321)
Browse files Browse the repository at this point in the history
* refactor: update {regr,classif}.ranger learner for 0.17.0

* chore: update NEWS.md

* chore: fix paramtest fro classif.ranger to exlucde regr-only param

* docs: add new ranger num.threads behavior docs

* chore: roxygenize

* refactor: make min.bucket and min.node.size a p_uty for classif.ranger to allow vector values
  • Loading branch information
jemus42 authored Nov 8, 2024
1 parent 83ef169 commit d9954ff
Show file tree
Hide file tree
Showing 25 changed files with 64 additions and 23 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# mlr3learners (development version)

compatibility: mlr3 0.22.0.
* feat: update hyperparameter set of `lrn("classif.ranger")` and `lrn("regr.ranger")` for 0.17.0, adding `na.action` parameter and `"missings"` property, and `poisson` splitrule for regression with a new `poisson.tau` parameter.
* compatibility: mlr3 0.22.0.


# mlr3learners 0.8.0

Expand Down
19 changes: 15 additions & 4 deletions R/LearnerClassifRanger.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#'
#' @section Initial parameter values:
#' - `num.threads`:
#' - Actual default: `NULL`, triggering auto-detection of the number of CPUs.
#' - Actual default: `2`, using two threads, while also respecting environment variable
#' `R_RANGER_NUM_THREADS`, `options(ranger.num.threads = N)`, or `options(Ncpus = N)`, with
#' precedence in that order.
#' - Adjusted value: 1.
#' - Reason for change: Conflicting with parallelization via \CRANpkg{future}.
#'
Expand Down Expand Up @@ -42,10 +44,19 @@ LearnerClassifRanger = R6Class("LearnerClassifRanger",
importance = p_fct(c("none", "impurity", "impurity_corrected", "permutation"), tags = "train"),
keep.inbag = p_lgl(default = FALSE, tags = "train"),
max.depth = p_int(default = NULL, lower = 1L, special_vals = list(NULL), tags = "train"),
min.bucket = p_int(1L, default = 1L, tags = "train"),
min.node.size = p_int(1L, default = NULL, special_vals = list(NULL), tags = "train"),
min.bucket = p_uty(default = 1L, tags = "train",
custom_check = function(x) {
if (checkmate::test_integerish(x)) return(TRUE)
"Must be integer of length 1 or greater"
}),
min.node.size = p_uty(default = NULL, special_vals = list(NULL), tags = "train",
custom_check = function(x) {
if (checkmate::test_integerish(x, null.ok = TRUE)) return(TRUE)
"Must be integer of length 1 or greater"
}),
mtry = p_int(lower = 1L, special_vals = list(NULL), tags = "train"),
mtry.ratio = p_dbl(lower = 0, upper = 1, tags = "train"),
na.action = p_fct(c("na.learn", "na.omit", "na.fail"), default = "na.learn", tags = "train"),
num.random.splits = p_int(1L, default = 1L, tags = "train", depends = quote(splitrule == "extratrees")),
node.stats = p_lgl(default = FALSE, tags = "train"),
num.threads = p_int(1L, default = 1L, tags = c("train", "predict", "threads")),
Expand All @@ -72,7 +83,7 @@ LearnerClassifRanger = R6Class("LearnerClassifRanger",
param_set = ps,
predict_types = c("response", "prob"),
feature_types = c("logical", "integer", "numeric", "character", "factor", "ordered"),
properties = c("weights", "twoclass", "multiclass", "importance", "oob_error", "hotstart_backward"),
properties = c("weights", "twoclass", "multiclass", "importance", "oob_error", "hotstart_backward", "missings"),
packages = c("mlr3learners", "ranger"),
label = "Random Forest",
man = "mlr3learners::mlr_learners_classif.ranger"
Expand Down
6 changes: 4 additions & 2 deletions R/LearnerRegrRanger.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ LearnerRegrRanger = R6Class("LearnerRegrRanger",
min.node.size = p_int(1L, default = 5L, special_vals = list(NULL), tags = "train"),
mtry = p_int(lower = 1L, special_vals = list(NULL), tags = "train"),
mtry.ratio = p_dbl(lower = 0, upper = 1, tags = "train"),
na.action = p_fct(c("na.learn", "na.omit", "na.fail"), default = "na.learn", tags = "train"),
node.stats = p_lgl(default = FALSE, tags = "train"),
num.random.splits = p_int(1L, default = 1L, tags = "train", depends = quote(splitrule == "extratrees")),
num.threads = p_int(1L, default = 1L, tags = c("train", "predict", "threads")),
num.trees = p_int(1L, default = 500L, tags = c("train", "predict", "hotstart")),
oob.error = p_lgl(default = TRUE, tags = "train"),
poisson.tau = p_dbl(default = 1, tags = "train", depends = quote(splitrule == "poisson")),
regularization.factor = p_uty(default = 1, tags = "train"),
regularization.usedepth = p_lgl(default = FALSE, tags = "train"),
replace = p_lgl(default = TRUE, tags = "train"),
Expand All @@ -51,7 +53,7 @@ LearnerRegrRanger = R6Class("LearnerRegrRanger",
se.method = p_fct(c("jack", "infjack"), default = "infjack", tags = "predict"), # FIXME: only works if predict_type == "se". How to set dependency?
seed = p_int(default = NULL, special_vals = list(NULL), tags = c("train", "predict")),
split.select.weights = p_uty(default = NULL, tags = "train"),
splitrule = p_fct(c("variance", "extratrees", "maxstat"), default = "variance", tags = "train"),
splitrule = p_fct(c("variance", "extratrees", "maxstat", "beta", "poisson"), default = "variance", tags = "train"),
verbose = p_lgl(default = TRUE, tags = c("train", "predict")),
write.forest = p_lgl(default = TRUE, tags = "train")
)
Expand All @@ -63,7 +65,7 @@ LearnerRegrRanger = R6Class("LearnerRegrRanger",
param_set = ps,
predict_types = c("response", "se", "quantiles"),
feature_types = c("logical", "integer", "numeric", "character", "factor", "ordered"),
properties = c("weights", "importance", "oob_error", "hotstart_backward"),
properties = c("weights", "importance", "oob_error", "hotstart_backward", "missings"),
packages = c("mlr3learners", "ranger"),
label = "Random Forest",
man = "mlr3learners::mlr_learners_regr.ranger"
Expand Down
1 change: 1 addition & 0 deletions inst/paramtest/test_paramtest_classif.ranger.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ test_that("classif.ranger", {
"class.weights", # handled via mlr3
"inbag", # handled via mlr3 stratification
"quantreg", # regression only
"poisson.tau", # regression only
"dependent.variable.name", # handled via mlr3
"status.variable.name", # handled via mlr3
"classification", # handled via mlr3
Expand Down
1 change: 1 addition & 0 deletions man/mlr_learners_classif.cv_glmnet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mlr_learners_classif.glmnet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mlr_learners_classif.kknn.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mlr_learners_classif.lda.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mlr_learners_classif.log_reg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mlr_learners_classif.multinom.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mlr_learners_classif.naive_bayes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/mlr_learners_classif.nnet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mlr_learners_classif.qda.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d9954ff

Please sign in to comment.