ranger_wrapper {nlpred} | R Documentation |
Wrapper for fitting a random forest using ranger.
Description
Compatible learner wrappers for this package should have a specific format.
Namely they should take as input a list called train
that contains
named objects $Y
and $X
, that contain, respectively, the outcomes
and predictors in a particular training fold. Other options may be passed in
to the function as well. The function must output a list with the following
named objects: test_pred
= predictions of test$Y
based on the learner
fit using train$X
; train_pred
= prediction of train$Y
based
on the learner fit using train$X
; model
= the fitted model (only
necessary if you desire to look at this model later, not used for internal
computations); train_y
= a copy of train$Y
; test_y
= a copy
of test$Y
.
Usage
ranger_wrapper(
train,
test,
num.trees = 500,
mtry = floor(sqrt(ncol(train$X))),
write.forest = TRUE,
probability = TRUE,
min.node.size = 5,
replace = TRUE,
sample.fraction = ifelse(replace, 1, 0.632),
num.threads = 1,
verbose = TRUE,
...
)
Arguments
train |
A list with named objects |
test |
A list with named objects |
num.trees |
See ranger. |
mtry |
See ranger. |
write.forest |
See ranger. |
probability |
See ranger. |
min.node.size |
See ranger. |
replace |
See ranger. |
sample.fraction |
See ranger. |
num.threads |
See ranger. |
verbose |
See ranger. |
... |
Other options (passed to |
Details
This particular wrapper implements the ranger ensemble methodology. We refer readers to the original package's documentation for more details.
Value
A list with named objects (see description).
Examples
# simulate data
# make list of training data
train_X <- data.frame(x1 = runif(50))
train_Y <- rbinom(50, 1, plogis(train_X$x1))
train <- list(Y = train_Y, X = train_X)
# make list of test data
test_X <- data.frame(x1 = runif(50))
test_Y <- rbinom(50, 1, plogis(train_X$x1))
test <- list(Y = test_Y, X = test_X)
# fit ranger
rf_wrap <- ranger_wrapper(train = train, test = test)