#| child: aaa.Rmd
#| include: false

r descr_models("rand_forest", "randomForest")

Tuning Parameters

#| label: randomForest-param-info
#| echo: false
defaults <- 
  tibble::tibble(parsnip = c("mtry", "trees", "min_n"),
                 default = c("see below", "500L", "see below"))

param <-
  rand_forest() |> 
  set_engine("randomForest") |> 
  make_parameter_list(defaults)

This model has r nrow(param) tuning parameters:

#| label: randomForest-param-list
#| echo: false
#| results: asis
param$item

mtry depends on the number of columns and the model mode. The default in [randomForest::randomForest()] is floor(sqrt(ncol(x))) for classification and floor(ncol(x)/3) for regression.

min_n depends on the mode. For regression, a value of 5 is the default. For classification, a value of 10 is used.

Translation from parsnip to the original package (regression)

#| label: randomForest-reg
rand_forest(
  mtry = integer(1),
  trees = integer(1),
  min_n = integer(1)
) |>  
  set_engine("randomForest") |> 
  set_mode("regression") |> 
  translate()

min_rows() and min_cols() will adjust the number of neighbors if the chosen value if it is not consistent with the actual data dimensions.

Translation from parsnip to the original package (classification)

#| label: randomForest-cls
rand_forest(
  mtry = integer(1),
  trees = integer(1),
  min_n = integer(1)
) |> 
  set_engine("randomForest") |> 
  set_mode("classification") |> 
  translate()

Preprocessing requirements

#| child: template-tree-split-factors.Rmd

Case weights

#| child: template-uses-case-weights.Rmd

Note that the data passed to the case.weights column are not used for traditional case weights (where the objective function is multiplied by a row-specific weight). From ?randomForest::randomForest: "A vector of length same asy that are positive weights used only in sampling data to grow each tree (not used in any other calculation)."

They function as sampling weights.

Saving fitted model objects

#| child: template-butcher.Rmd

Prediction types

#| label: predict-types

parsnip:::get_from_env("rand_forest_predict") |>
  dplyr::filter(engine == "randomForest") |>
  dplyr::select(mode, type)

Examples

The "Fitting and Predicting with parsnip" article contains examples for rand_forest() with the "randomForest" engine.

References



Try the parsnip package in your browser

Any scripts or data that you put into this service are public.

parsnip documentation built on May 14, 2026, 5:08 p.m.