Skip to contents

Coercion methods to BenchmarkAggr. For mlr3::BenchmarkResult this is a simple wrapper around the BenchmarkAggr constructor called with mlr3::BenchmarkResult$aggregate().

Usage

as.BenchmarkAggr(
  obj,
  task_id = "task_id",
  learner_id = "learner_id",
  independent = TRUE,
  strip_prefix = TRUE,
  ...
)

Arguments

obj

(mlr3::BenchmarkResult|matrix(1))
Passed to BenchmarkAggr$new().

task_id, learner_id, independent, strip_prefix

See BenchmarkAggr$initialize().

...

ANY
Passed to mlr3::BenchmarkResult$aggregate().

Examples

df = data.frame(tasks = factor(rep(c("A", "B"), each = 5),
                               levels = c("A", "B")),
                learners = factor(paste0("L", 1:5)),
                RMSE = runif(10), MAE = runif(10))

as.BenchmarkAggr(df, task_id = "tasks", learner_id = "learners")
#> <BenchmarkAggr> of 10 rows with 2 tasks, 5 learners and 2 measures
#>     tasks learners       RMSE       MAE
#>  1:     A       L1 0.16703681 0.3812115
#>  2:     A       L2 0.97895632 0.2558161
#>  3:     A       L3 0.08437176 0.5651859
#>  4:     A       L4 0.07509937 0.1297404
#>  5:     A       L5 0.58178853 0.2279997
#>  6:     B       L1 0.93441621 0.8017235
#>  7:     B       L2 0.25682867 0.8973348
#>  8:     B       L3 0.05649689 0.1636037
#>  9:     B       L4 0.69183235 0.8169671
#> 10:     B       L5 0.55987702 0.4542707


if (requireNamespaces(c("mlr3", "rpart"))) {
  library(mlr3)
  task = tsks(c("boston_housing", "mtcars"))
  learns = lrns(c("regr.featureless", "regr.rpart"))
  bm = benchmark(benchmark_grid(task, learns, rsmp("cv", folds = 2)))

  # default measure
  as.BenchmarkAggr(bm)

  # change measure
  as.BenchmarkAggr(bm, measures = msr("regr.rmse"))
}
#> <BenchmarkAggr> of 4 rows with 2 tasks, 2 learners and 1 measure
#>           task_id  learner_id     rmse
#> 1: boston_housing featureless 9.339177
#> 2: boston_housing       rpart 2.040312
#> 3:         mtcars featureless 6.087346
#> 4:         mtcars       rpart 6.087346