Skip to contents

Setup hyperparameters for Ranger Random Forest training.

Usage

setup_Ranger(
  num_trees = 500L,
  mtry = NULL,
  importance = "impurity",
  write_forest = TRUE,
  probability = FALSE,
  min_node_size = NULL,
  min_bucket = NULL,
  max_depth = NULL,
  replace = TRUE,
  sample_fraction = ifelse(replace, 1, 0.632),
  case_weights = NULL,
  class_weights = NULL,
  splitrule = NULL,
  num_random_splits = 1L,
  alpha = 0.5,
  minprop = 0.1,
  poisson_tau = 1,
  split_select_weights = NULL,
  always_split_variables = NULL,
  respect_unordered_factors = NULL,
  scale_permutation_importance = FALSE,
  local_importance = FALSE,
  regularization_factor = 1,
  regularization_usedepth = FALSE,
  keep_inbag = FALSE,
  inbag = NULL,
  holdout = FALSE,
  quantreg = FALSE,
  time_interest = NULL,
  oob_error = TRUE,
  save_memory = FALSE,
  verbose = TRUE,
  node_stats = FALSE,
  seed = NULL,
  na_action = "na.learn",
  ifw = FALSE
)

Arguments

num_trees

(Tunable) Integer [1, Inf): Number of trees.

mtry

(Tunable) Optional Integer [1, Inf): Number of features to consider at each split.

importance

Character {"none", "impurity", "impurity_corrected", "permutation"}: Variable importance mode. "impurity" is the Gini index for classification, the response variance for regression.

write_forest

Logical: If TRUE, save the forest object (required for prediction). Set to FALSE to reduce memory if no prediction is intended.

probability

Logical: If TRUE, grow a probability forest. Classification only.

min_node_size

(Tunable) Optional Integer [1, Inf): Minimal node size. If NULL, ranger uses 1 for classification, 5 for regression, 3 for survival, and 10 for probability.

min_bucket

Optional Integer [1, Inf): Minimal number of samples in a terminal node. Survival only. Deprecated in favor of min_node_size.

max_depth

(Tunable) Optional Integer [0, Inf): Maximal tree depth. NULL or 0 means unlimited depth, 1 means tree stumps.

replace

(Tunable) Logical: If TRUE, sample with replacement.

sample_fraction

(Tunable) Numeric (0, 1]: Fraction of observations to sample. Default is 1 with replacement and 0.632 without.

case_weights

Optional Numeric [0, Inf) vector: Per-observation sampling weights; larger weights raise selection probability in each tree's sample.

class_weights

Optional Numeric [0, Inf) vector: Per-class weights for classification. Length equal to the number of classes, named by class label.

splitrule

(Tunable) Optional Character: Splitting rule. Classification: "gini", "extratrees", "hellinger"; regression: "variance", "extratrees", "maxstat", "beta"; survival: "logrank", "extratrees", "C", "maxstat".

num_random_splits

(Tunable) Integer [1, Inf): Number of random splits per candidate variable, for the "extratrees" splitrule.

alpha

(Tunable) Numeric [0, 1]: Significance threshold to allow splitting, for the "maxstat" splitrule.

minprop

(Tunable) Numeric [0, 1]: Lower quantile of the covariate distribution considered for splitting, for the "maxstat" splitrule.

poisson_tau

Numeric (0, Inf): Tau parameter, for the "poisson" regression splitrule.

split_select_weights

Optional List: Per-feature probabilities of being selected for splitting, in [0, 1]. One vector applied to every tree, or a list of length num_trees with one vector per tree.

always_split_variables

Optional Character vector: Names of variables to always include as split candidates, in addition to the mtry variables.

respect_unordered_factors

Optional Character {"partition", "ignore", "order"}: Handling of unordered factors. "partition" considers all 2-partitions, "ignore" orders levels by first occurrence, "order" orders levels by mean response.

scale_permutation_importance

Logical: If TRUE, scale permutation importance by its standard error. Permutation importance only.

local_importance

Logical: If TRUE, compute local (per-observation) permutation importance.

regularization_factor

(Tunable) Numeric [0, Inf): Regularization factor penalizing variables with many split points. Requires splitrule = "variance".

regularization_usedepth

Logical: If TRUE, apply the regularization factor with node depth. Requires regularization_factor.

keep_inbag

Logical: If TRUE, record how often each observation is in-bag per tree.

inbag

Optional List: Manually set in-bag counts; a list of length num_trees, each a per-case count vector. Can be used for stratified sampling.

holdout

Logical: If TRUE, use hold-out mode: hold out samples with case weight 0 and use them for variable importance and prediction error.

quantreg

Logical: If TRUE, prepare quantile prediction (quantile regression forests). Regression only; set keep_inbag = TRUE for out-of-bag quantile prediction.

time_interest

Optional Numeric vector: Time points of interest for survival prediction. Survival only. Deprecated.

oob_error

Logical: If TRUE, compute the OOB prediction error. Set to FALSE to save time if only the forest is needed.

save_memory

Logical: If TRUE, use the memory-saving (slower) splitting mode. Use only if you encounter memory problems.

verbose

Logical: If TRUE, show computation status and estimated runtime.

node_stats

Logical: If TRUE, save additional node statistics (terminal nodes only).

seed

Optional Integer: Random seed. If NULL, the seed is generated from R. Set to 0 to ignore the R seed.

na_action

Character {"na.learn", "na.omit", "na.fail"}: How to handle missing values. "na.learn" uses observations with missing values in splitting, treating missing as a separate category.

ifw

(Tunable) Logical: If TRUE, use Inverse Frequency Weighting in classification.

Value

RangerHyperparameters object.

Details

Get more information from ranger::ranger.

Author

EDG

Examples

ranger_hyperparams <- setup_Ranger(num_trees = 1000L, ifw = FALSE)
ranger_hyperparams
#> <RangerHyperparameters>
#>         hyperparameters: 
#>                                             num_trees: <int> 1000
#>                                                  mtry: <NUL> NULL
#>                                            importance: <chr> impurity
#>                                          write_forest: <lgc> TRUE
#>                                           probability: <lgc> FALSE
#>                                         min_node_size: <NUL> NULL
#>                                            min_bucket: <NUL> NULL
#>                                             max_depth: <NUL> NULL
#>                                               replace: <lgc> TRUE
#>                                       sample_fraction: <nmr> 1.00
#>                                          case_weights: <NUL> NULL
#>                                         class_weights: <NUL> NULL
#>                                             splitrule: <NUL> NULL
#>                                     num_random_splits: <int> 1
#>                                                 alpha: <nmr> 0.50
#>                                               minprop: <nmr> 0.10
#>                                           poisson_tau: <nmr> 1.00
#>                                  split_select_weights: <NUL> NULL
#>                                always_split_variables: <NUL> NULL
#>                             respect_unordered_factors: <NUL> NULL
#>                          scale_permutation_importance: <lgc> FALSE
#>                                      local_importance: <lgc> FALSE
#>                                 regularization_factor: <nmr> 1.00
#>                               regularization_usedepth: <lgc> FALSE
#>                                            keep_inbag: <lgc> FALSE
#>                                                 inbag: <NUL> NULL
#>                                               holdout: <lgc> FALSE
#>                                              quantreg: <lgc> FALSE
#>                                         time_interest: <NUL> NULL
#>                                             oob_error: <lgc> TRUE
#>                                           save_memory: <lgc> FALSE
#>                                               verbose: <lgc> TRUE
#>                                            node_stats: <lgc> FALSE
#>                                                  seed: <NUL> NULL
#>                                             na_action: <chr> na.learn
#>                                                   ifw: <lgc> FALSE
#> tunable_hyperparameters: <chr> num_trees, mtry, min_node_size, max_depth, replace, sample_fraction, splitrule, num_random_splits, alpha, minprop, regularization_factor, ifw
#>   fixed_hyperparameters: <chr> importance, write_forest, probability, min_bucket, case_weights, class_weights, poisson_tau, split_select_weights, always_split_variables, respect_unordered_factors, scale_permutation_importance, local_importance, regularization_usedepth, keep_inbag, inbag, holdout, quantreg, time_interest, oob_error, save_memory, verbose, node_stats, seed, na_action
#>                   tuned: <int> -1
#>               resampled: <int> 0
#>               n_workers: <int> 1
#> 
#>   No search values defined for tunable hyperparameters.