LearnerRanger | R Documentation |
The LearnerRanger
class is the interface to the ranger
R package for use
with the mlexperiments
package.
Optimization metric:
classification: classification error rate
regression: mean squared error Can be used with
mlexperiments::MLTuneParameters
mlexperiments::MLCrossValidation
mlexperiments::MLNestedCV
mlexperiments::MLLearnerBase
-> LearnerRanger
new()
Create a new LearnerRanger
object.
LearnerRanger$new()
A new LearnerRanger
R6 object.
LearnerRanger$new()
clone()
The objects of this class are cloneable with this method.
LearnerRanger$clone(deep = FALSE)
deep
Whether to make a deep clone.
ranger::ranger()
# binary classification
library(mlbench)
data("PimaIndiansDiabetes2")
dataset <- PimaIndiansDiabetes2 |>
data.table::as.data.table() |>
na.omit()
seed <- 123
feature_cols <- colnames(dataset)[1:8]
param_list_ranger <- expand.grid(
num.trees = seq(500, 1000, 500),
mtry = seq(2, 6, 2),
min.node.size = seq(1, 9, 4),
max.depth = seq(1, 9, 4),
sample.fraction = seq(0.5, 0.8, 0.3)
)
train_x <- model.matrix(
~ -1 + .,
dataset[, .SD, .SDcols = feature_cols]
)
train_y <- as.integer(dataset[, get("diabetes")]) - 1L
fold_list <- splitTools::create_folds(
y = train_y,
k = 3,
type = "stratified",
seed = seed
)
ranger_cv <- mlexperiments::MLCrossValidation$new(
learner = mllrnrs::LearnerRanger$new(),
fold_list = fold_list,
ncores = 2,
seed = 123
)
ranger_cv$learner_args <- c(
as.list(
data.table::data.table(
param_list_ranger[37, ],
stringsAsFactors = FALSE
),
),
list(classification = TRUE)
)
ranger_cv$performance_metric_args <- list(positive = "1")
ranger_cv$performance_metric <- mlexperiments::metric("auc")
# set data
ranger_cv$set_data(
x = train_x,
y = train_y
)
ranger_cv$execute()
## ------------------------------------------------
## Method `LearnerRanger$new`
## ------------------------------------------------
LearnerRanger$new()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.