Learn R Programming

dtGAP (version 0.0.2)

train_rf: Fit a Conditional Random Forest

Description

Fits a conditional random forest using partykit::cforest() and returns the forest object along with variable importance scores.

Usage

train_rf(
  data_train,
  target_lab,
  task = c("classification", "regression"),
  ntree = 500L,
  mtry = NULL,
  control = NULL
)

Value

A list with elements:

forest

The fitted cforest object.

var_imp

A named numeric vector of relative variable importance (scaled to sum to 1 and rounded to two decimals).

ntree

Integer. Number of trees in the forest.

Arguments

data_train

Data frame. Training data.

target_lab

Character. Name of the target column.

task

Character. "classification" or "regression".

ntree

Integer. Number of trees (default 500).

mtry

Integer or NULL. Number of variables randomly sampled at each split. If NULL, uses the cforest default.

control

A ctree_control object or NULL.

Examples

Run this code
# \donttest{
data(train_covid)
rf_res <- train_rf(train_covid, target_lab = "Outcome", ntree = 50)
rf_res$var_imp
# }

Run the code above in your browser using DataLab