Skip to contents

This function allows to construct or convert to a ResultData object, the result container used by ResampleResult and BenchmarkResult. A ResampleResult or BenchmarkResult can be initialized with the returned object. Note that ResampleResults can be converted to a BenchmarkResult with as_benchmark_result() and multiple BenchmarkResults can be combined to a larger BenchmarkResult with the $combine() method of BenchmarkResult.

Usage

as_result_data(
  task,
  learners,
  resampling,
  iterations,
  predictions,
  learner_states = NULL,
  data_extra = NULL,
  store_backends = TRUE
)

Arguments

task

(Task).

learners

(list of trained Learners).

resampling

(Resampling).

iterations

(integer()).

predictions

(list of list of Predictions)
One list for each iteration, containing the predictions named with the predict set, e.g. list(test = prediction).

learner_states

(list())
Learner states. If not provided, the states of learners are automatically extracted.

data_extra

(list())
Additional data for each iteration.

store_backends

(logical(1))
If set to FALSE, the backends of the Tasks provided in data are removed.

Value

ResultData object which can be passed to the constructor of ResampleResult.

Examples

task = tsk("penguins")
learner = lrn("classif.rpart")
resampling = rsmp("cv", folds = 2)$instantiate(task)
iterations = seq_len(resampling$iters)

# manually train two learners.
# store learners and predictions
learners = list()
predictions = list()
for (i in iterations) {
  l = learner$clone(deep = TRUE)
  learners[[i]] = l$train(task, row_ids = resampling$train_set(i))
  predictions[[i]] = list(test = l$predict(task, row_ids = resampling$test_set(i)))
}

rdata = as_result_data(task, learners, resampling, iterations, predictions)
ResampleResult$new(rdata)
#> 
#> ── <ResampleResult> with 2 resampling iterations ───────────────────────────────
#>   task_id    learner_id resampling_id iteration     prediction_test warnings
#>  penguins classif.rpart            cv         1 <PredictionClassif>        0
#>  penguins classif.rpart            cv         2 <PredictionClassif>        0
#>  errors
#>       0
#>       0