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_benchmark_aggr(
  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_benchmark_aggr(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.1197089 0.9689532
#>  2:     A       L2 0.7020482 0.4389878
#>  3:     A       L3 0.1748738 0.5224602
#>  4:     A       L4 0.4117146 0.1327346
#>  5:     A       L5 0.6761042 0.5782789
#>  6:     B       L1 0.8840769 0.9950841
#>  7:     B       L2 0.8748552 0.9103015
#>  8:     B       L3 0.2907559 0.3498349
#>  9:     B       L4 0.3680931 0.8409293
#> 10:     B       L5 0.6419954 0.3926148


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_benchmark_aggr(bm)

  # change measure
  as_benchmark_aggr(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.183588
#> 2: boston_housing       rpart 1.850790
#> 3:         mtcars featureless 5.996558
#> 4:         mtcars       rpart 5.996558