setup_Ranger: Setup Ranger Hyperparameters

View source: R/070_Hyperparameters.R

setup_RangerR Documentation

Setup Ranger Hyperparameters

Description

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),
  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): Fewest cases a terminal node may hold; no split creates a smaller node. Unset uses ranger's default of 1.

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.

class_weights

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

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. NULL gives every feature the same probability.

always_split_variables

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

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. NULL draws each tree's sample by replace and sample_fraction, with the training case weights as sampling weights where train supplies them.

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. NULL uses the observed event times.

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.

Details

Get more information from ranger::ranger.

Value

RangerHyperparameters object.

Author(s)

EDG

Examples

ranger_hyperparams <- setup_Ranger(num_trees = 1000L, ifw = FALSE)
ranger_hyperparams

rtemis documentation built on Oct. 20, 2026, 1:06 a.m.