LearnerRanger {mllrnrs}R Documentation

R6 Class to construct a Ranger learner

Description

The LearnerRanger class is the interface to the ranger R package for use with the mlexperiments package.

Details

Optimization metric:

Super class

mlexperiments::MLLearnerBase -> LearnerRanger

Methods

Public methods

Inherited methods

Method new()

Create a new LearnerRanger object.

Usage
LearnerRanger$new()
Returns

A new LearnerRanger R6 object.

Examples
LearnerRanger$new()


Method clone()

The objects of this class are cloneable with this method.

Usage
LearnerRanger$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

ranger::ranger()

Examples

# 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()


[Package mllrnrs version 0.0.4 Index]