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
#>     <fctr>   <fctr>     <num>      <num>
#>  1:      A       L1 0.8737686 0.48209023
#>  2:      A       L2 0.4438671 0.07904644
#>  3:      A       L3 0.3247907 0.25579946
#>  4:      A       L4 0.4504828 0.56770732
#>  5:      A       L5 0.7649633 0.31155450
#>  6:      B       L1 0.9087629 0.36487585
#>  7:      B       L2 0.1655570 0.32065847
#>  8:      B       L3 0.8828185 0.57593691
#>  9:      B       L4 0.2957749 0.79170309
#> 10:      B       L5 0.9689389 0.45660585


if (requireNamespaces(c("mlr3", "rpart"))) {
  library(mlr3)
  task = tsks(c("pima", "spam"))
  learns = lrns(c("classif.featureless", "classif.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("classif.acc"))
}
#> <BenchmarkAggr> of 4 rows with 2 tasks, 2 learners and 1 measure
#>    task_id  learner_id       acc
#>     <fctr>      <fctr>     <num>
#> 1:    pima featureless 0.6510417
#> 2:    pima       rpart 0.7356771
#> 3:    spam featureless 0.6059566
#> 4:    spam       rpart 0.9030644